Unix/Linux Go Back    

Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

[Template] Send SMTP email with Visual Basic Script (vbs) from Command Prompt using CDO

Windows & DOS: Issues & Discussions

Thread Tools Search this Thread Display Modes
Old Unix and Linux 07-25-2012   -   Original Discussion by Tribe
Tribe's Unix or Linux Image
Tribe Tribe is offline
Registered User
Join Date: Jul 2012
Last Activity: 9 September 2017, 5:03 AM EDT
Posts: 52
Thanks: 44
Thanked 4 Times in 4 Posts
[Template] Send SMTP email with Visual Basic Script (vbs) from Command Prompt using CDO

This is a script in visual basic that basically sends an email from an existing account, in this case the example is provided for live.com. It uses CDO (Collaboration Data Objects).

All you need to do is replace the fields with the proper information.

The email is send from Command Prompt with either

script smtp_cdo.vbs
wscript smtp_cdo.vbs

option explicit
    Dim objMail  
    Set objMail = CreateObject("CDO.Message")  
    'sender email address  
    objMail.From = "Sender <sender@live.com>"  
    'Receiver email address  
    objMail.To = "Receiver <dest@email.com>"  
    'Email subject  
    objMail.Subject = "This is the testing email subject"  
    'Email Body  
    objMail.Textbody = "This is the my first email send by vb script"  
    'If you need to attache a file,can do in this way.  
    'objMail.AddAttachment "C:\myphoto.jpg"  
    'Configure SMTP server  
    objMail.Configuration.Fields.Item _  
        ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2  
    'Here you should configure name or IP of the SMTP server  
    objMail.Configuration.Fields.Item _  
        ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.live.com" 
    ' SMTP port need to configure here (Default 25)  
    objMail.Configuration.Fields.Item _  
        ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587 
    const cdoBasic=1
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "sender@live.com"
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpaccountname") = "sender@live.com"
    objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
    'update the field in message object   
    'sending email  
    'clear mail object  
    Set objMail=Nothing  
    'exit the script  

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Enable send email through smtp - exchange on AIX 6.1 ichsan AIX 1 08-09-2011 03:03 AM
Script to send email after comparing the folder permissions to a certain permission & send email nairshar Shell Programming and Scripting 2 12-07-2010 08:22 PM
How do I send email from command prompt? munna_dude Programming 0 04-10-2007 04:12 AM
Send email using Exchange as SMTP fidodido UNIX for Dummies Questions & Answers 2 01-20-2006 09:05 AM

All times are GMT -4. The time now is 12:40 PM.