<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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        color:black;}
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;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";
        color:black;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas","serif";
        color:black;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";
        color:black;}
.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 bgcolor=white lang=EN-NZ link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>I think from memory that was to do with the SMTP component being already connected to another server. Must have been a good reason at the time...<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";color:windowtext'>From:</span></b><span lang=EN-US style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> delphi-bounces@delphi.org.nz [mailto:delphi-bounces@delphi.org.nz] <b>On Behalf Of </b>David<br><b>Sent:</b> Tuesday, 12 July 2011 8:26 p.m.<br><b>To:</b> delphi@delphi.org.nz<br><b>Subject:</b> Re: [DUG] Email/SMTP code<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>Erm...<br>I understand your code works, but you probably want to remove this bit. <br>The RFC doesn't require a pause<o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:#1F497D'> t := now ;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:#1F497D'> while (SMTP.Connected) and</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:#1F497D'> (now < t + 10 * (1/86400)) do // 10 Seconds</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> sleep(10) ;<br><br></span>Also, to get around the mailservers that block you ( e.g. when they don't know you, or think you're a spam bot)<br>just relay the message through your own ISP<br>e.g. if you're with orcon, use mail.orcon.net.nz, if you're with ihug, use their smtp server...<br>As long as you have the correct destination email addresses (and aren't in fact writing a spam bot), the big mail servers can do the work for you<br><br>David<br><br>On 12/07/2011 2:01 p.m., David O'Brien wrote: <o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>Wrote this a while ago, but still works...</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> </span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>procedure SendEmail(msgFrom, msgTo, msgSubject: String; msgBody: TStringList; Attachments: TStringList) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>var</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage: TIdMessage;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP: TIdSMTP;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> t: TDateTime ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> i: Integer ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>begin</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> try</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> if ASettings.SMTPServer <> '' then</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> begin</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP := TidSMTP.Create(nil) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage := TIdMessage.Create(SMTP);</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> try</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Clear ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.From.Address := msgFrom ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Recipients.Add.Address := msgTo ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.Subject := msgSubject ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> if pos('<html', lowercase(msgBody.Text)) <> 0 then</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> idMessage.ContentType := 'text/html' ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> if msgBody <> nil then</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage.Body.Assign(msgBody) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> t := now ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> while (SMTP.Connected) and</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> (now < t + 10 * (1/86400)) do // 10 Seconds</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> sleep(10) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> if Assigned(Attachments) then</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> for i := 0 to pred(Attachments.Count) do</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> TIdAttachmentFile.Create(IdMessage.MessageParts, Attachments[i]) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Host := ASettings.SMTPServer ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Port := ASettings.SMTPPort ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Username := ASettings.Username ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Password := ASettings.Password ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Connect ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> try</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Send(idMessage) ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> finally</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Disconnect ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> end ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> finally</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> SMTP.Free ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> IdMessage.Free ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> end;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> end;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> except</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> EmailFailed := True ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> end ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>end ;</span><o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'> </span><o:p></o:p></p><div><div style='border:none;border-top:solid windowtext 1.0pt;padding:3.0pt 0cm 0cm 0cm;border-color:-moz-use-text-color -moz-use-text-color'><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"'> <a href="mailto:delphi-bounces@delphi.org.nz">delphi-bounces@delphi.org.nz</a> [<a href="mailto:delphi-bounces@delphi.org.nz">mailto:delphi-bounces@delphi.org.nz</a>] <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</span><o:p></o:p></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"'>Anyone got a recommendation for the best (free) code/samples to drive Indy10 for sending an email with attachment</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>-Indy10.2.3</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>-Send attachment</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>-SMTP server and email addresses will be known</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>I have tried a couple (eg AtoZed SendMail example) but it seems to time out connecting to the SMTP </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> </span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'>John</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Arial","sans-serif"'> </span><o:p></o:p></p></div></div></div><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><br><br>__________ Information from ESET Smart Security, version of virus signature database 6285 (20110711) __________<br><br>The message was checked by ESET Smart Security.<br><br><a href="http://www.eset.com">http://www.eset.com</a><br><br><o:p></o:p></span></p><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>_______________________________________________<o:p></o:p></pre><pre>NZ Borland Developers Group - Delphi mailing list<o:p></o:p></pre><pre>Post: <a href="mailto:delphi@delphi.org.nz">delphi@delphi.org.nz</a><o:p></o:p></pre><pre>Admin: <a href="http://delphi.org.nz/mailman/listinfo/delphi">http://delphi.org.nz/mailman/listinfo/delphi</a><o:p></o:p></pre><pre>Unsubscribe: send an email to <a href="mailto:delphi-request@delphi.org.nz">delphi-request@delphi.org.nz</a> with Subject: unsubscribe<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><o:p> </o:p></pre><pre>__________ Information from ESET Smart Security, version of virus signature database 6285 (20110711) __________<o:p></o:p></pre><pre><o:p> </o:p></pre><pre>The message was checked by ESET Smart Security.<o:p></o:p></pre><pre><o:p> </o:p></pre><pre><a href="http://www.eset.com">http://www.eset.com</a><o:p></o:p></pre><pre><o:p> </o:p></pre><p class=MsoNormal><span style='font-size:12.0pt;font-family:"Times New Roman","serif"'><o:p> </o:p></span></p></div></body></html>