Send word file as intext Email

bluesoulcurrybluesoulcurry Member Posts: 25
Hello All,

I am using the below code to send word file as an in-text Email. The word file basically is a campaign file with few pictures and text here and there.
          IF ISCLEAR(objOL) THEN
            CREATE(objOL, FALSE, TRUE);

          objNS := objOL.GetNamespace('MAPI');
          IF SMTPInfo.FINDFIRST THEN BEGIN
            FromMail := SMTPInfo."User ID";
            FromPwd := SMTPInfo.Password;
          END;

          objNS.Logon(FromMail, FromPwd, FALSE, TRUE);

          InteractionTemplateRec.SETRANGE("Campaign No.", CampaignNo);

          IF InteractionTemplateRec.FINDFIRST THEN BEGIN
            InteractionTemplateRec.CALCFIELDS("Attachment No.");
            IF AttachmentRec.GET(InteractionTemplateRec."Attachment No.") THEN BEGIN
              AttachmentPath := 'C:\Temp\attachment.docx';
              AttachmentRec.ExportAttachment(AttachmentPath);
              IF ISCLEAR(wdApp) THEN
                CREATE(wdApp, FALSE, TRUE);
              wdDoc := wdApp.Documents.Open(AttachmentPath);
              objMail := wdDoc.MailEnvelope.Item;
              objMail.Display(FALSE);
              objMail.BodyFormat := 2;
              objMail.Subject := InteractionTemplateRec."E-mail Subject";
              objMail."To" := ToEmail;
              objMail.Send;
              wdDoc.Close;
              CLEAR(wdDoc);
              CLEAR(wdApp);
            END;
          END;
          CLEAR(objOL);
        END;

I have to send this E-mail to multiple recipients which are approximately between 250-450. This code works fine until around 100-110 emails. Then it starts throwing the below error, and stops sending email.
This message is for C/AL programmers: The call to member MailEnvelope failed: Unspecified error (Exception from HRESULT: 0x80004005(E_FAIL)).

I have searched through various forums, but not able to find the reason what part of the code is throwing error. I would be really thankful, if you guys can help me resolve the issue.

Thanks in advance.

Comments

  • kylehardinkylehardin Member Posts: 257
    The SMTP server may have a limit on the number of addresses you can add per message, probably for spam or virus prevention. First thing I would try would be to limit each message to 100 addresses - have nested loops and create a new (identical) message for each 100 addresses.
    Kyle Hardin - ArcherPoint
  • herrlutzherrlutz Member Posts: 58
    would be interested if this has been solved.
    I guess it´s worth a Customer Source support call...
Sign In or Register to comment.