Multiple attachments via codeunit 397 (mail) : again...

BGIBGI Member Posts: 176
I have seen a lot of solutions to the problem of putting multiple attachments in a mail message created via codeunit 397.
But or i'm not looking correctly, but i didn't found any:using the 397 codeunit version 3.70,4.00.. (the one with automation.) and putting multiple attachments on it.
Why i'm looking for it?
To finaly have a codeunit where you can:
- use multiple, nice formated body lines (with the function addbodyline)
- use multiple recipients ..

and use multiple attachments...
Rgds
Benny Giebens

Comments

  • alfred58alfred58 Member Posts: 12
    you can repeat this code for mutiple attachements:


    IF AttachFileName <> '' THEN BEGIN
    BSTRConverterAttachFileName.ResetBSTR;
    BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileName);
    OAttachments := OSendMail.Attachments;
    OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
    END;
  • mihusoftmihusoft Member Posts: 1
    Hy,

    if checked the functionality with up to 100 attachments.
    The solution of the problem is very simple, if you know how. :wink:

    1) Create a new Function in codeunit 397 identical to the function NewMessage, let's call it "NewMessageMultipleAttachments".
    2) Replace the field "AttachFileName" by an array called e.g. "AttachFileNames".
    3) Assign number of dimensions you need.
    (The calling function must fit with the number of dimensions used here)
    4) Modify the part
    IF AttachFileName <> '' THEN BEGIN
          BSTRConverterAttachFileName.ResetBSTR;
          BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileName);
          OAttachments := OSendMail.Attachments;
          OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
        END;
    
    like this
    FOR FileNameCounter:= 1 TO ARRAYLEN(AttachFileNames) DO BEGIN
         IF AttachFileNames[FileNameCounter] <> '' THEN BEGIN
           BSTRConverterAttachFileName.ResetBSTR;
           BSTRConverterAttachFileName.AppendNextStringPortion(AttachFileNames[FileNameCounter]);
           OAttachments := OSendMail.Attachments;
           OAttachment := OAttachments.Add(BSTRConverterAttachFileName);
         END;
       END;
    
    5) At least you have do define and fill up an array in your mail-calling function.

    This should work fine

    I hope, this tiny little code will help you and others to send multiple attachments from MS Dynamics.
    Who wants to live in ease,
    should not communicate his knowledge,
    and not believe he knows form hearsay.
  • Torben_R.Torben_R. Member Posts: 99
    Please inform me how to create the variables

    BSTRConverterAttachFileName
    OAttachments
    OSendMail
    OAttachment
Sign In or Register to comment.