We help IT Professionals succeed at work.

send email using vbscript

metropia
metropia asked
on
hello I would like to send an email with an html link in the body using a visual basic script that gets executed by a scheduled task.

I am using the script attached on the code screen, but I keep getting an error that reads:

CDO.Message.1 error '80040220' The "SendUsing" configuration value is invalid.



Set objMessage = CreateObject("CDO.Message") 

objMessage.Subject = "Daily Status Report" 
objMessage.From = "generic@company.com" 
objMessage.To = "distributionlist@company.com"

objMessage.HTMLBody = "<p>Good Morning! This is an automated message sent every morning at 4:30 AM.</p>" 

objMessage.CreateMHTMLBody "http://company.com:8080/do/getCrystalReport?reportId=216&reportFormat=PDF"

objMessage.Send

Open in new window

Comment
Watch Question

I would suggest using Blat instead as it's much easier. I have used it before in the past for automation. Take a look at thier example page.

http://www.blat.net/



Top Expert 2011
Commented:
Try following...modify to your smtp server "smtp.myserver.com"
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Daily Status Report" 
objMessage.From = "generic@company.com" 
objMessage.To = "distributionlist@company.com"
objMessage.CreateMHTMLBody "http://company.com:8080/do/getCrystalReport?reportId=216&reportFormat=PDF"

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.myserver.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Open in new window

Author

Commented:
I am having problems formatting the property objMessage.CreateMHTMLBody
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Daily Shipping Status Report - North Branch."
objMessage.From = "@.com"
objMessage.To = "@.com"
objMessage.HTMLBody = "<p>Good Morning! This is an automated message sent every morning at 4:30 AM.</p>" 
objMessage.CreateMHTMLBody "<a href="http://web..com:8080/do/getCrystalReport?reportId=216&reportFormat=PDF">" & "Daily Shipping Status</a>"

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.joplin.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Open in new window

Line 6 needs a pair of double-quotes [""] on the embedded double-quotes.
objMessage.CreateMHTMLBody "<a href=""http://web..com:8080/do/getCrystalReport?reportId=216&reportFormat=PDF"">" & "Daily Shipping Status</a>"

Open in new window

Also, I believe you meant "web.com"?  Or was it web.something.com and you just deleted the "something"?

Author

Commented:
i edited those values.

let me try it again.

thanks!

Author

Commented:
I got a syntax error pointing to that same line :(


dim objMessage
dim strMsg

Set objMessage = CreateObject("CDO.Message")

objMessage.Subject = "Daily Shipping Status Report."
objMessage.From = "reports@"
objMessage.To = "@.com"


objMessage.HTMLBody = "<p>Good Morning! This is an automated message sent every morning at 4:30 AM.</p>"
objMessage.CreateMHTMLBody "<a href=""http://web.foo.com:8080/do/getCrystalReport?reportId=216&reportFormat=PDF"">" & "Daily Shipping Status</a>"



'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.morrison.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send
Commented:
just removed objMessage.CreateMHTMLBod property

and put everything within objMessage.HTMLBody

thanks!

Author

Commented:
I am accepting my comment as part of the solution because that was the last workaround, in order to make the code provided by prashanthd.

Thanks!