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