How to attach more than 1 file in an e-mail using cu 397

Hi all!

We’re sending an e-mail to the customer with the order confirmation as an PDF-file. In addition we would like to attach another PDF-file.

I tried to create a new function “NewMessageTwoAttach” to add an extra attachment file like this

MAPIHandler.AttachFileName := AttachFileName;

IF AttachFileName2 <> ‘’ THEN
MAPIHandler.AttachFileName := AttachFileName2;

MAPIHandler.OpenDialog := OpenDialog;

but that doesn’t work.

Any input, or better, a solution that works (without using any other variables etc?

Thanks,

You might want to look at this VB link on using MAPI. http://www.codeguru.com/forum/archive/index.php/t-249703.html By using the MAPIMessages.MsgNoteText property and indexing the attachement postions I was able to add multiple attachements. I wanted to have from 1 to 8 attachements plus 2 attachements of a different type after the others. I found that if I there was a blank attachement space then the rest of the attachements after that one would be left off. I found I could get around that by shifting attachements in an array until all positions were filled from the 1st. postion to X. Here is a sample of the attachement MsgNotText and indexing.

IF AttachFileName0 = ‘’ THEN
MAPIMessages.MsgNoteText := Body; //If no attachment

IF AttachFileName0 <> ‘’ THEN BEGIN
MAPIMessages.MsgNoteText := Body + ’ '; //One Attachment
MAPIMessages.AttachmentIndex := 0;
MAPIMessages.AttachmentPosition := 0;
MAPIMessages.AttachmentType := 0;
MAPIMessages.AttachmentPathName := AttachFileName0;
END;

IF AttachFileName1 <> ‘’ THEN BEGIN
MAPIMessages.MsgNoteText := Body + ’ ’ + ’ '; //Two Attachments
MAPIMessages.AttachmentIndex := 1;
MAPIMessages.AttachmentPosition := 1;
MAPIMessages.AttachmentType := 0;
MAPIMessages.AttachmentPathName := AttachFileName1;
END;

IF AttachFileName2 <> ‘’ THEN BEGIN
MAPIMessages.MsgNoteText := Body + ’ ’ + ’ ’ + ’ '; //Three Attachments
MAPIMessages.AttachmentIndex := 2;
MAPIMessages.AttachmentPosition := 2;
MAPIMessages.AttachmentType := 0;
MAPIMessages.AttachmentPathName := AttachFileName2;
END;

Here is a sample of moving the attachement positions:

// Code to shift BOLPDF and XLS to first blank attachement spaces. This is necessary or attachments after
// a blank attachment place holder will fail.
FOR i := 1 TO 8 DO
BEGIN
IF Attachment[i] = ‘’ THEN BEGIN
Attachment[i] := BOLAttachment;
Attachment[i+1] := SpreadsheetAttachment;
i := 8;
Shifted := TRUE;
END
END;

IF NOT Shifted THEN BEGIN
Attachment[9] := BOLAttachment;
Attachment[10] := SpreadsheetAttachment;
END;

EmailMessage := EmailMessage + FORMAT(chr13)+FORMAT(Chr10) + FORMAT(chr13)+FORMAT(Chr10);
Body := 'XYZ Material Cert. Packet for '+BOLNO;
MAPI.NewMessageMultipleAttachements([xxx@xyz.com, 'Cert](mailto:xxx@xyz.com, ‘Cert). Packet’,Body,
Attachment[1],Attachment[2],Attachment[3],Attachment[4],Attachment[5],Attachment[6],
Attachment[7],Attachment[8],Attachment[9],Attachment[10],FALSE);
END;