Blogs

How to send an Email with attachment via the DI API
Lisa Mulchinock SAP Employee
Business Card
Company: SAP
Posted on Oct. 08, 2009 12:24 AM in SAP Business One

Subscribe.Subscribe
Print. Print
Permalink Permalink

In this blog we will demonstrate how to send an email with an attachment using both the Message Object and Message Service. Attachments are represented in the SAP Business One DI API from version 2005 via the Attachments2 object. This enables the user to copy files from a source folder to the Attachments folder.

Ensure first that you define the attachments folder in Administration -> System Initialisation -> General Settings. If this is not done you will receive an error such as "Source Files does not exist".

The Message Object is the 'old' way of utilising the functionality. To add the attachment to the email we call the Attachments subobject of the Messages object and provide the location of the file name.

 

image

 

As you know SAP recommends that partners use Services in add-ons. All new functionality will in future be released as a service and not an object. To send an email using Message Services we first need to add the attachment.

 

image

 

In the path you defined in Administration->System Initialization->General 
Setting->Path, every attachment will first be copied to this path. If there is already a file with the same name of the one you are attempting to attach the SAP Business One DI API will try to copy it first to the default path and will then return an error message that the file name exists.       

Once the attachment is added we need to link the attachment/document to the email by setting the AttachmentEntry value. This corresponds to the AbsoluteEntry of the newly added attachment and in our example this is 2. This is stored in the the table ATC1.

 

image

 

Lisa Mulchinock is a senior SDK support consultant for SAP Business One.


Add to: del.icio.us | Digg | Reddit


Comment on this articleIf anything in unclear or if you have additional questions regarding how to send an email with an attachment feel free to add a comment here.
Comment on this weblog
Showing messages 1 through 2 of 2.

Titles Only Main Topics Oldest First

  • Cannot uderstand 2
    2009-10-14 05:24:17 Manish Kumar Business Card [Reply]

    Hi i cuold not understand oMessage.attachment = 2.


    what is 2??

    • Cannot uderstand 2
      2009-10-14 14:47:49 Lisa Mulchinock SAP Employee Business Card [Reply]

      Hi Manish,


      As you can see in our example we first add an attachment using the Attachment2 object - in this case we add an attchment called Log.txt.


      Once the attachment is added we need to link the attachment/document to the email by setting the AttachmentEntry value. This corresponds to the AbsoluteEntry of the newly added attachment and in our example it is 2. You can find this value by querying the table ATC1.


      Cheers,
      Lisa


Showing messages 1 through 2 of 2.