API document amendment - How to add an attachment via the API onto an Email in GoldMine

Version 1

    Details

    API Document amendment - How to add an attachment via the API onto an Email in GoldMine





    Resolution

    [INFORMATION]
    In addition to the information available in the current GoldMine API document (please refer to related Knowledge Article # 17603 - GoldMine API Integration Guide the following information may help developers to handle attachments for example on outgoing / queued emails.


    Please keep in mind that GoldMine Technical Support can only provide limited support for API inquiries and we always recommend to submit your inquiry on the virtual community https://community.goldmine.com/


     

    The key functions are SaveMail and QueueMail

     

    The SaveMail function enables you to save a mail message into GoldMine when the actual sending or retrieval of the message took place already outside the application. 

    The folder/subfolder specified to save the message to will be created by GoldMine if needed. There’s no need to create it beforehand.

     

    The QueueMail function queues a message for delivery. The actual delivery is not handled through the DLL. It is  recommended to set up a specific user in GoldMine responsible for sending multiple users’ mail on a regular basis. If the message to be queued already exists within GoldMine, pass either the Mailbox RecID or the Calendar/History RecID  with the history flag. When queuing a new message, do not provide values for the RecID name/value pairs or the flag.

     

    For further information regarding these and other complementary functions please refer to GoldMine API Guide

     

    Below there are a few examples of code in C++ that are using the functions described above for manipulating emails with attachments.


    As it is described in the GoldMine API Guide, there are several ways to access the API so that a developer can use the one that fits better the current needs.

     

    Examples:

     

    //Reading an existing email

    GMW_LoadAPI("c:\\ProgramData\\GoldMine", "GoldMine:", "GoldMine:", "master", "access");

     

    1 -

    //Reading an email

    HGMNV vals = GMW_NV_Create();

    GMW_NV_SetValue(vals, "RecID", "JGSHE2H)HI.A W<");

    long result = GMW_Execute("ReadMail", vals);

     

    //Checks some values from the read email

    std::string sRecId = MW_NV_GetValue(vals, "RecID", "NOT READ");

    std::string sTo = MW_NV_GetValue(vals, "To", "NOT READ");

    GMW_NV_Delete(vals);

     

    GMW_UnloadAPI();

     

    2 -

    //Saving an email with an attachment

     

    GMW_LoadAPI("c:\\ProgramData\\GoldMine", "GoldMine:", "GoldMine:", "master", "access");

    //Creates a Queued mail

    HGMNV vals = GMW_NV_Create();

    //Creates a new mail in the inbox (by default)

    HGMNV vals = GMW_NV_Create();

    GMW_NV_SetValue(vals, "To", "[email protected]");

    GMW_NV_SetValue(vals, "From", "[email protected]");

    GMW_NV_SetValue(vals, "Subject", "Testing save 01");

    GMW_NV_SetValue(vals, "Bodytext", "Testing save 01");

    GMW_NV_SetValue(vals, "NumAttachments", "1");

    GMW_NV_SetValue(vals, "Attachment0", "C:\\temp\\goldmine1.jpg");

                 

    long result = GMW_Execute("SaveMail", vals);

    GMW_NV_Delete(vals);

     

    GMW_UnloadAPI();

     

     

    3-

    // Queuing an email with an attachment

    GMW_LoadAPI("c:\\ProgramData\\GoldMine", "GoldMine:", "GoldMine:", "master", "access");

    //Creates a Queued mail

    HGMNV vals = GMW_NV_Create();

    GMW_NV_SetValue(vals, "To", "[email protected]");

    GMW_NV_SetValue(vals, "From", "[email protected]");

    GMW_NV_SetValue(vals, "Subject", "Testing 02");

    GMW_NV_SetValue(vals, "Bodytext", "1 2 3 testing");

    GMW_NV_SetValue(vals, "NumAttachments", "1");

    GMW_NV_SetValue(vals, "Attachment0", "C:\\temp\\goldmine1.jpg");

          

    long result = GMW_Execute("QueueMail", vals);

     

    GMW_NV_Delete(vals);

    GMW_UnloadAPI();