Script Issue : Sending email with an Attachment via Outlook

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
cyberic68
Newbie
Posts: 4
Joined: Thu Oct 16, 2014 1:03 pm

Script Issue : Sending email with an Attachment via Outlook

Post by cyberic68 » Thu Jan 22, 2015 8:20 pm

Hi

I would like to use this script to send email with an Attachment via OutLook, I'm getting an VBScript runtime error 438 with it, due to the fact that the line about the .AddAttachment seems not to be recognized (see below)

If I remove that Line about the .AddAttachment, everything works ok, I receive the email with the HTMLbody

Could someone correct my error ?

Thanks

Eric

==================================================


VBStart
Function CreateEmail(strRecipient, strSubject, strHTML)
'Create OL App object
Set objOLApp = CreateObject("Outlook.Application")

If objOLApp is nothing then
MsgBox "Could not create OL App. Shutting Down"
Exit Function
End If

'Create a new mail item
Set objMsg = objOLApp.CreateItem(0)
If objMsg is nothing then
MsgBox "Could not create Mail Item. Shutting Down"
Exit Function
End If

'Set basic message parameters
objMsg.To = strRecipient
objMsg.Subject = strSubject
objMsg.HTMLBody = strHTML
objMsg.AddAttachment "C:\daily_report.txt"
objMsg.Send

'Free up the space
Set objOLApp = Nothing
Set objMsg = Nothing

CreateEmail = "Success"
End Function
VBEnd

Let>strTo=[email protected]
Let>strSubj=Daily_Report
Let>strHTML="<html><body>Hi Everyone,<br><br>Eric<br></body></html>"
VBEval>CreateEmail("%strTo%","%strSubj%",%strHTML%), Anwser

cyberic68
Newbie
Posts: 4
Joined: Thu Oct 16, 2014 1:03 pm

SOLVED-Script Issue:Sending email with an Attachment via Out

Post by cyberic68 » Fri Jan 23, 2015 2:25 am

Solved !!!

With Outlook it's a bit different, instead of this line

objMsg.AddAttachment "C:\daily_report.txt"

you need this

objMsg.Attachments.Add "C:\daily_report.txt"

That's it, it works perfectly

Eric

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts