Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: How to add attachment to SMTP email?
| Subject: | Re: How to add attachment to SMTP email? |
| Posted by: | "Debby Beatty" (datapathdesi..@earthlink.net) |
| Date: | Wed, 18 Oct 2006 09:56:12 |
Thank you! I am using 10, which is why the examples I downloaded did not
work. I'll try this today.
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:4535b8db$1@newsgroups.borland.com...
>
> "Debby Beatty" <datapathdesign@earthlink.net> wrote in message
> news:45359bd4$1@newsgroups.borland.com...
>
> > How do I add an attachment?
>
> Create an instance of a TIdAttachment class and add it to the
> TIdMessage.MessageParts collection.
>
> > I have this working, but don't know what to do next:
>
> Try this:
>
> procedure TMyEMail.SendMail(vFromAddress, vFromName, vToAddress,
> vSubject, vBodyText, vLogFile, vAttachment: string);
> begin
> IdMessage.Clear;
>
> IdMessage1.From.Address := vFromAddress;
> IdMessage1.From.Name := vFromName;
> IdMessage1.Recipients.EMailAddresses := vToAddress;
> IdMessage1.Subject := vSubject;
>
> if vAttachment <> '' then
> begin
> with TIdText.Create(IdMessage1.MessageParts, nil) do
> begin
> Body.Text := vBodyText;
> ContentType := 'text/plain';
> end;
>
> // if you are using Indy 10, then use TIdAttachmentFile
instead
> with TIdAttachment.Create(IdMessage1.MessageParts,
vAttachment)
> do
> begin
> ContentType := GetMimeTypeFromFile(vAttachment);
> end;
>
> IdMessage1.ContentType := 'multipart/mixed';
> end else
> begin
> IdMessage1.Body.Add(vBodyText);
> IdMessage1.ContentType := 'text/plain';
> end;
>
> try
> SMTP.Connect;
> try
> SMTP.Send(IdMessage1);
> finally
> SMTP.Disconnect;
> end;
> except
> on E:Exception do
> Application.MessageBox(PChar(E.Message), 'ERROR: ' ,
MB_OK);
> end;
>
> if vLogFile <> '' then
> WriteToLog(vFromAddress, vToAddress, vSubject, vLogFile);
> end;
>
>
> Gambit
none