Subject: | Message with attachment sometimes puts attachment in body of mail |
Posted by: | Ross McMillan (nospam@gmail.com) |
Date: | Fri, 9 Dec 2005 |
I'm sending a plain text email with a PDF file as an attachment. It works
fine here "in the lab" but the customer gets different results - he doesn't
see the separate attachment as such - it appears in base 64 in the body of
the email. I guess it's because I'm not assigning to ContentType anywhere,
but I don't understand how it worked here. Also, is it OK to use the same
code (as I am doing below) to send a plain text email, and send a plain text
email with attachments? From the examples I have read the two cases are
hadled somewhat differently.
The code is:
EmailJob := TEmailJob.Create ;
with EmailJob do
begin
ejMessage.Body.Clear ;
ejMessage.Body.Add (ejBody) ;
ejMessage.From.Text := ejFromAddress ;
ejMessage.Recipients.EmailAddresses := ejToAddress ;
ejMessage.Subject := ejSubject ;
ejMessage.ReceiptRecipient.Text := '' ;
if (parAttachmentFileID1 <> '') then
begin
if FileExists (parAttachmentFileID1) then
begin
TIdAttachmentFile.Create (ejMessage.MessageParts,
parAttachmentFileID1) ;
if (parAttachmentFileID2 <> '') then
begin
if FileExists (parAttachmentFileID2) then
begin
TIdAttachmentFile.Create (ejMessage.MessageParts,
parAttachmentFileID2) ;
end
else
begin
ejResult := pterAttachmentFileNotFound ;
end ;
end ;
end
else
begin
ejResult := pterAttachmentFileNotFound ;
end ;
end ;
if (ejResult <> pterOK) then
begin
EmailJob.Free ;
end
else
begin
EmailPool.Add (EmailJob) ;
end ;
end ;