We help IT Professionals succeed at work.

Delphi 2009 & Indy 10 email attachments

gerhard9121
gerhard9121 asked
on
2,765 Views
Last Modified: 2012-05-07
I am upgrading from Delphi 7 with Indy 9 to Delphi 2009 and Indy 10.

I get Indy to attach a document to a email but the recipient receives a email with the attachment names ATT????.Dat although I attached a PDF file. If the recipient save's this as a PDF file it is the correct file.

How can I get Indy to send the correct attachment name.
MSG.Clear;
        if tbEmPendAttachment.Value <> '' then
        begin
          l_attachment := MailDir + '\' + tbEmPendAttachment.Value;
          TIdAttachmentFile.Create(Msg.MessageParts,l_attachment);
        end;
        if tbEmPendAttachment2.Value <> '' then
        begin
          MailFile := TIdAttachmentFile.Create(Msg.MessageParts,
          tbEmPendAttachment2.Value);
          MailFile.DisplayName := Msg.Subject;
        end;
        MSG.From.Text := Trim(tbEmPendFrom.Value);
        MSG.ReplyTo.EMailAddresses := Trim(tbEmPendFrom.Value);
        MSG.Recipients.EMailAddresses := trim(tbEMPendTo.Value);
        MSG.Subject := tbEmPendSubject.Value;
        MSG.ReceiptRecipient.Text := tbEmPendFrom.Value;
        l_body := TStringList.Create;
        l_body.Text := tbEmPendNote.Value;
        MSG.Body.Assign(l_body);
        l_body.Free;
        SMTP.Send(Msg);

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:
I had to solve the same issue but I don't remember exactly how I did it. I think it had something to do with AttachmentEncoding.

Try adding this line some where prior to making your attachment.
MSG.AttachmentEncoding  := 'MIME';

Author

Commented:
Tried adding MSG.AttachmentEncoding  := 'MIME' but it still attaches a ATT?????.Dat
CERTIFIED EXPERT

Commented:
Well it did take a fair amount of trial and error on my part to figure it out.
Also may need to add:
MSG.Encoding := meMIME;

Author

Commented:
MSG.Encoding := meMIME;

This makes no difference. Any other suggestion please
CERTIFIED EXPERT

Commented:
Have you tried setting:
MailFile.Filename := tbEmPendAttachment2.Value;

Author

Commented:
I have changed my code but no luck so far
    l_attachment := MailDir + '\' + tbEmPendAttachment.Value;
    MailFile := TIdAttachmentFile.Create(Msg.MessageParts,l_attachment);
    MSG.Encoding := meMime;
    Mailfile.FileName := tbEmPendAttachment.Value;

Open in new window

CERTIFIED EXPERT

Commented:
Sorry, I know I have gone through this same stuff but I cannot remember exactly what solved it for me. If I stumble accross it I will post.

Author

Commented:
Thanks for your help sofar. I have been battling with this for a couple of days and require a solution urgently

Author

Commented:
The problem is with the version of Indy10 distributed with Delphi 2009. I downloaded the latest Indy after deleting all older indy file and recompiled Indy. Everything went well but cant load the dclIndyProtocols package. According to Indy it is because I still have old Indy files but I have checked this and still think it is an error in their source code.
CERTIFIED EXPERT

Commented:
When you say "can't load dclIndyProtocols package" - what happens, an error?
When that happens it's usually a problem with the library path

Author

Commented:
I receive the following errro:

'The procdure entry point @Idheadercoderindy@anitialization&qqrv could not be located in the dynamik link library IndyProtocals120.bplgerhardodendaal
 
Software Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
As I previously stated the problem was in teh version of Indy distributed with Delph 2009. I loaded the latest version of Indy but could not get the components to load. I bypassed this problem by creating them at runtime.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.