VB/VBS email sending code

Source: Internet
Author: User
Tags email account
Vbs email sending code

NameSpace = "http://schemas.microsoft.com/cdo/configuration"
Set Email = CreateObject ("CDO. Message ")
Email. From = "Benio_Guo@sohu.com"
Email. To = "Benio_Guo@126.com"
Email. Subject = "say hello"
Email. Textbody = "test body"
Email. AddAttachment ""
With Email. Configuration. Fields
. Item (NameSpace & "sendusing") = 2
. Item (NameSpace & "smtpserver") = "smtp.sohu.com"
. Item (NameSpace & "smtpserverport") = 25
. Item (NameSpace & "smtpauthenticate") = 1
. Item (NameSpace & "sendusername") = "benio_guo"
. Item (NameSpace & "sendpassword") = "q1w2e3"
. Update
End
Email. Send. below is the vb version.

Private Sub Form_Load ()
Dim NameS As String
Dim Email As Object

NameS = "http://schemas.microsoft.com/cdo/configuration"

Set Email = CreateObject ("CDO. Message ")
Email. From = "Benio_Guo@sohu.com"
Email. To = "Benio_Guo@126.com"
Email. Subject = "say hello"
Email. Textbody = "test body"
Email. AddAttachment "C: \ test.txt"
Email. Configuration. Fields. Item (NameS & "sendusing") = 2
Email. Configuration. Fieds. Item (NameS & "smtpserver") = "smtp.sohu.com"
Email. Configuration. Fields. Item (NameS & "smtpserverport") = 25
Email. Configuration. Fields. Item (NameS & "smtpauthenticate") = 1
Email. Configuration. Fields. Item (NameS & "sendusername") = "benio_guo"
Email. Configuration. Fields. Item (NameS & "sendpassword") = "q1w2e3"
Email. Configuration. Fields. Update
Email. Send
End Sub

2: 'Save the following file as a vbs file, and double-click it to run it. You can also run it in the Job.
Set cdo = CreateObject ("CDO. Message ")
StrCfg = "http://schemas.microsoft.com/cdo/configuration"
With cdo
. Sender = "Sender's email address"
. From = "sender's email address"
. To = "recipient's email address"
. Fields ("urn: schemas: mailheader: X-Priority") = 1
. Fields. Update
. Subject = "mail title"
. TextBody = "email content"
. Configuration (strCfg & "SendUsing") = 2
. Configuration (strCfg & "smtpserver") = "mail server address"
. Configuration (strCfg & "sendusername") = "sender email account"
. Configuration (strCfg & "sendpassword") = "sender's email password"
. Configuration. Fields. Update
. Send
End
Msgbox "sent successfully"

NameSpace = "http://schemas.microsoft.com/cdo/configuration"
Set Email = CreateObject ("CDO. Message ")
Email. From = "Benio_Guo @ cn. *. com"
Email. To = "Benio_Guo @ cn. *. com"
Email. Subject = "Daily Planned Order Report _" & year (now () & month (now () & day (now ())
'X = "C: \ test.txt"
Y = "K: \ ASCP \ reports \ APS_PLAN_ORDER_FOR_RELEASE_BY_WEEKLY_DR.xls"
'Set fso = CreateObject ("Scripting. FileSystemObject ")
'Set myfile = fso. OpenTextFile (x, 1, Ture)
'C = myfile. readall
'Myfile. Close
'Email. Textbody = c
Email. AddAttachment y
With Email. Configuration. Fields
. Item (NameSpace & "sendusing") = 2
. Item (NameSpace & "smtpserver") = "dm01"
. Item (NameSpace & "smtpserverport") = 25
. Item (NameSpace & "smtpauthenticate") = 1
. Item (NameSpace & "sendusername") = "benio guo"
. Item (NameSpace & "sendpassword") = "* pwd *"
. Update
End
Email. Send
Set Email = Nothing

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.