Skip to Content

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.

9 Comments
You must be Logged on to comment or reply to a post.
  • 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

  • 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

  • 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.