Reputation: 383
I want to send an email from my vbscript code, the below code is working properly on my machine, but when I changed my machine, the code is no more able to send email. There were no errors or problems occurred during run, but no emails were sent/delivered. Has anyone else faced a problem like this?
Set objMessage = CreateObject("CDO.Message")
With objMessage
.From = SendFrom
.To = SendTo
.Subject = "Subject"
.Textbody = ""
.HTMLBody = "<b>Body</b>"
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.Gmail.Com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Username"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"
.Update
End With
.Send
End With
Upvotes: 0
Views: 3328
Reputation: 11
You need to install CDonts library first. Search on microsoft.com for CDONTS library and install the same.
If you want to send without installation then try the second method. you have to initialize the objects. In that example i remove h in the link because i can't post links
CDO.MESSAGE
'Script to send an email through QTP nice one Set oMessage = CreateObject("CDO.Message")
'==This section provides the configuration information for the remote SMTP server. '==Normally you will only change the server name or IP. oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserver") =""
'Server port (typically 25) oMessage.Configuration.Fields.Item _ ("ttp://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update oMessage.Subject = "Test Mail" oMessage.Sender = "" oMessage.To ="" 'oMessage.CC = "" 'oMessage.BCC = "" oMessage.TextBody = "Test Mail from QTP"&vbcrlf&"Regards,"&vbcrlf&"Test" oMessage.Send
Set oMessage = Nothing
Upvotes: 0
Reputation: 200373
First, since you didn't post the entire code, check that your script doesn't contain a line
On Error Resume Next
If it does: remove the line and try again.
If you don't have that line in your script and the script doesn't raise an error and you can telnet mailserver 25
then it's almost certain that the mail server accepted the mail for delivery and the problem is somewhere upstream. Check the mail server logs.
You can verify if the server actually accepts mail like this:
C:\>
telnet mailserver 25
220 mailserver ESMTP
HELO clientname
250 mailserver
MAIL FROM:<[email protected]>
250 2.1.0 Ok
RCPT TO:<[email protected]>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test
test
.
250 2.0.0 Ok: queued as 4541E2227
QUIT
The line before the QUIT
command means that the server accepted the mail. The actual response text may vary depending on which MTA is used, but every MTA will respond with some line like that when it accepts a message.
Upvotes: 1
Reputation: 2752
I would imagine this is a permissions issue or a firewall issue if it is working on your machine but not the production machine. Carefully look at what is different, is one behind the firewall and other is not?
Upvotes: 1