Add attachment to your mail in BODS- A step by step process
Hello Techbie’s,
I had a requirement to send email with attachment in bods.
I read through some of the article in SCN but none of it provided a detailed way of achieving it.
I found the article (Add an attachment to BODS Job Notification email using VB Script ) somewhat interesting but it was not working for me
So I did a little research and came up with a solution that can be implemented in BODS.
Solution:-
We’ll do it using vb script and then calling that script in our job.
Step 1: Use below code to make a vb script file.
Open a notepad, write below code by making necessary changes to highlighted text and then save it as email.vbs
Option Explicit
Dim MyEmail
Set MyEmail=CreateObject(“CDO.Message”)
MyEmail.Subject = “Subject Line”
MyEmail.From = “no-reply@yourcompany.com“
MyEmail.To = ” helpdesk@yourcompany.com “
MyEmail.TextBody = “This is the message body.”
MyEmail.AddAttachment “attachment file path” — NO EQUAL TO SIGN HERE
(Note: Attachment filepath – This has to be a shared directory or location which is accessible by the DS. Common mistake people include “equal to ‘=’ “sign near Add attachment which results in an error)
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing“)= 2
‘SMTP Server
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver“)= “smtp relay server name”
‘SMTP Port
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport“)= 25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
Step 2: In Job place the below script:
Script_Email which includes a call to email.vbs script file:
e.g. exec(‘cscript’,’filepath\email1.vbs’, 8);
Filepath where email.vbs is located.
Try the below.. It should work!!
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "XYZ"
objMessage.From = "abc@xyz.com"
objMessage.To = "abc@xyz.com"
objMessage.TextBody = "data is here attached." & vbcrlf
objMessage.AddAttachment "<Path>\Exceptions.xls"
'==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") = "1.1.1.1"
'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
Regards.
Shaz
Hello Shazin,
You almost written the same thing which I've documented above.
Thanks for your comment.
Oops.. sorry never went through your script. This is the working script in my environment. Please can you advise on the error you are getting. Have you checked if the antivirus in your environment has not blocked port 25 as this was one of the problem we faced while setting up the environment few months back.
Regards.
Shaz
Shazin,
Thanks for replying. Previously I was getting the error but I've rectified it with the code specified above.
Hope this will be useful for other people.
Nice explanation
objMessage.AddAttachment "<Path>\Exceptions.xls"
Here how to take xls file as target
Hi Shaz,
May i know function behind this link : http://schemas.microsoft.com/cdo/configuration/sendusing . how to configure the same?
Please provide your suggestion.
Hi Gokul,
The script worked for me but now I want to pass a few arguments into the vb script, do you know the correct syntax? I need to pass in the TO email addresses, the attachment file path, and attachment filename from the BODS job.
Thank you,
Ben
Hello,
what is the function behind this link http://schemas.microsoft.com/cdo/configuration/sendusing and How do i configure the same?
Please suggest.
Regards
Bhupen
Hi Gokul,
I am using the same code that you are using but it is not sending any mail. I can send mails when I use direct smtp_to but below script is not sending mail.
Option Explicit
Dim MyEmail
Set MyEmail=CreateObject(“CDO.Message”)
MyEmail.Subject = “Subject Line”
MyEmail.From = “**********@gmail.com“
MyEmail.To = ”***********@gmail.com“
MyEmail.TextBody = “This is the message body.”
MyEmail.AddAttachment “C:\temp\order.txt”
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/sendusing“)= 2
‘SMTP Server
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserver“)= “172.XX.X.XX”
‘SMTP Port
MyEmail.Configuration.Fields.Item (“http://schemas.microsoft.com/cdo/configuration/smtpserverport“)= 25
MyEmail.Configuration.Fields.Update
MyEmail.Send
set MyEmail=nothing
Please help me to solve this issue.
Thanks & Regards,
Ramana.
any solution to this above?