<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>Wrote this a while ago, but still works...<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>procedure SendEmail(msgFrom, msgTo, msgSubject: String; msgBody: TStringList; Attachments: TStringList) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>var<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage: TIdMessage;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP: TIdSMTP;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> t: TDateTime ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> i: Integer ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>begin<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> try<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> if ASettings.SMTPServer <> '' then<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> begin<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP := TidSMTP.Create(nil) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage := TIdMessage.Create(SMTP);<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> try<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Clear ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.From.Address := msgFrom ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Recipients.Add.Address := msgTo ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Subject := msgSubject ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> if pos('<html', lowercase(msgBody.Text)) <> 0 then<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.ContentType := 'text/html' ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> if msgBody <> nil then<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage.Body.Assign(msgBody) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> t := now ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> while (SMTP.Connected) and<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> (now < t + 10 * (1/86400)) do // 10 Seconds<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> sleep(10) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> if Assigned(Attachments) then<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> for i := 0 to pred(Attachments.Count) do<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> TIdAttachmentFile.Create(IdMessage.MessageParts, Attachments[i]) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Host := ASettings.SMTPServer ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Port := ASettings.SMTPPort ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Username := ASettings.Username ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Password := ASettings.Password ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Connect ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> try<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Send(idMessage) ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> finally<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Disconnect ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> end ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> finally<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Free ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage.Free ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> end;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> end;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> except<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> EmailFailed := True ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'> end ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>end ;<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <b>On Behalf Of </b>John Bird<br><b>Sent:</b> Tuesday, 12 July 2011 1:47 p.m.<br><b>To:</b> NZ Borland Developers Group - Delphi List<br><b>Subject:</b> [DUG] Email/SMTP code<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>Anyone got a recommendation for the best (free) code/samples to drive Indy10 for sending an email with attachment<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>-Indy10.2.3<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>-Send attachment<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>-SMTP server and email addresses will be known<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>I have tried a couple (eg AtoZed SendMail example) but it seems to time out connecting to the SMTP <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> <o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'>John<o:p></o:p></span></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif";color:black'> <o:p></o:p></span></p></div></div></div></div></body></html>