can't send a email
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
can't send a email
Hi,
my scrpit is as below, but can't send email successfully, who do you know the reason
Sub MainTest
NameSpace = "http://schemas.microsoft.com/cdo/configuration/"
set Email = CreateObject("CDO.Message")
Email.From = "smiletonghaiyan85@163.com"
Email.To = "smiletonghaiyan85@163.com"
Email.Subject = "send email"
x="C:\Users\H208139\Desktop\New Text Document.txt"
Email.Textbody = "hello"
Email.AddAttachment x
with Email.Configuration.Fields
.Item(NameSpace&"sendusing") = 2
.Item(NameSpace&"smtpserver") = "smtp.163.com"
.Item(NameSpace&"smtpserverport") = 25
.Item(NameSpace&"smtpauthenticate") = 1
.Item(NameSpace&"sendusername") = "smiletonghaiyan85"
.Item(NameSpace&"sendpassword") = "********"
.Update
end with
Email.Send
Set Email=Nothing
End Sub
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do you get any error messages in the log when you try?
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@nikki85 Try using this and look for proper port numbers and authentication type.
Function SendEmail(mFrom, mTo, mSubject, mBody, mAttachment) Dim smtpServer, smtpPort, userLogin, userPassword Dim authenticationType, useSSL, connectionTimeout Dim schema, mConfig, mMessage smtpServer = "SERVER NAME" smtpPort = 465 'port number userLogin = "USERNAME" ' e.g. "abc" if the address is abc@gmail.com userPassword = "PASSWORD" authenticationType = 1 ' cdoBasic connectionTimeout = 30 useSSL = True Err.Clear() On Error Resume Next schema = "http://schemas.microsoft.com/cdo/configuration/" Set mConfig = Sys.OleObject("CDO.Configuration") mConfig.Fields.Item(schema & "sendusing") = 2 ' cdoSendUsingPort mConfig.Fields.Item(schema & "smtpserver") = smtpServer mConfig.Fields.Item(schema & "smtpserverport") = smtpPort mConfig.Fields.Item(schema & "sendusername") = userLogin mConfig.Fields.Item(schema & "sendpassword") = userPassword mConfig.Fields.Item(schema & "smtpauthenticate") = authenticationType mConfig.Fields.Item(schema & "smtpusessl") = useSSL mConfig.Fields.Item(schema & "smtpconnectiontimeout") = connectionTimeout mConfig.Fields.Update() Set mMessage = Sys.OleObject("CDO.Message") Set mMessage.Configuration = mConfig mMessage.From = mFrom mMessage.To = mTo mMessage.Subject = mSubject mMessage.HTMLBody = mBody If 0 < Len(mAttachment) Then mMessage.AddAttachment(mAttachment) End If mMessage.Send() If Err.Number > 0 Then Call Log.Error("E-mail cannot be sent", Err.Description) SendEMail = False Err.Clear() Else Log.Message("Message to <" & mTo & "> was successfully sent") SendEMail = True End If End Function
Also, do post the error if you see any in error log
