VBScript email sending script..need modification..

Posted on 2011-04-26
Last Modified: 2012-05-11
Hello Experts ..

I have this code which successfully sends email if i use our SMTP server.If external or public like gmail is used it wont work.. I would like to know how can we modify it to send email using public SMTP servers as well.

SMTPServer = "mx1.*****.com"
Recipient = ""
From = ""
Subject = "Test email"
Message = "This is the email subject"

GenericSendmail SMTPserver, From, Recipient, Subject, Message

Sub GenericSendmail (SMTPserver, From, Recipient, Subject, Message)

set msg = WScript.CreateObject("CDO.Message")
msg.From = From
msg.To = Recipient
msg.Subject = Subject
msg.TextBody = Message
msg.Configuration.Fields ("") = SMTPServer
msg.Configuration.Fields("") = 2
End Sub

Open in new window

Thank you much for looking into this ..
Question by:subhashchy
    LVL 12

    Expert Comment

    LVL 8

    Author Comment

    can you please explain how it works..i am no voice in VBscript
    LVL 12

    Accepted Solution

    Try the requires authentication, so give your username and password.
    SMTPServer = "mx1.*****.com"
    mailTo = ""
    mailFrom = ""
    Subject = "Test email"
    Message = "This is the email subject"
    Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
    Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = subject
    objMessage.From = mailFrom
    objMessage.To = mailTo
    objMessage.TextBody = message
    '==This section provides the configuration information for the remote SMTP server.
    objMessage.Configuration.Fields.Item _
    ("") = 2
    'Name or IP of Remote SMTP Server
    objMessage.Configuration.Fields.Item _
    ("") = smtpserver
    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("") = cdoBasic
    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("") = username
    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("") = password
    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("") = 25
    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("") = False
    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("") = 60
    '==End remote SMTP server configuration section==

    Open in new window

    LVL 8

    Assisted Solution

    Here is a function I use to send through GMail.
    Sub SendEmailGMail(sSubject, sEmailText, sGmailEmailAddress, sGmailPassword, sTo)
        Set oEmail = CreateObject("CDO.Message")
        oEmail.From = sGmailEmailAddress
        oEmail.To = sTo
        oEmail.Subject = sSubject
        oEmail.HTMLbody = sEmailText
        sSchema = ""
        oEmail.Configuration.Fields.Item(sSchema & "sendusing") = 2
        oEmail.Configuration.Fields.Item(sSchema & "smtpserver") = ""
        oEmail.Configuration.Fields.Item(sSchema & "smtpserverport") = 465
        oEmail.Configuration.Fields.Item(sSchema & "smtpauthenticate") = 1
        oEmail.Configuration.Fields.Item(sSchema & "sendusername") = sGmailEmailAddress
        oEmail.Configuration.Fields.Item(sSchema & "sendpassword") = sGmailPassword
        oEmail.Configuration.Fields.Item(sSchema & "smtpusessl") = 1
        oEmail.Configuration.Fields.Item(sSchema & "smtpconnectiontimeout") = 60
        Set oEmail = Nothing
    End Sub

    Open in new window

    LVL 8

    Author Closing Comment

    Thanks  for the help guys..both script is working fine. Much appreciated.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now