[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   
    objMail.Configuration.Fields.Update  
      
    'sending email  
    objMail.Send  
      
    'clear mail object  
    Set objMail=Nothing  
      
    'exit the script  
    Wscript.Quit