<HTML xmlns="http://www.w3.org/TR/REC-html40" 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"><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<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>
</HEAD>
<BODY dir=ltr lang=EN-NZ vLink=purple link=blue>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">
<DIV>FYI Your original version had a small error in it that you fixed in the
later version you posted – at the IdMessage.free line – which I should already
been free’d by the previous SMTP.free, ie the IdMessage.free was not
needed</DIV>
<DIV> </DIV>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">John</DIV>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt"> </DIV>
<DIV style="FONT-FAMILY: 'Arial'; COLOR: #000000; FONT-SIZE: 10pt">
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none"><B>From:</B>
<A title=Dave@iccs.co.nz href="mailto:Dave@iccs.co.nz">David O'Brien</A> </DIV>
<DIV style="FONT: 10pt tahoma">
<DIV style="BACKGROUND: #f5f5f5">
<DIV><B>Sent:</B> Tuesday, July 12, 2011 2:01 PM</DIV>
<DIV><B>To:</B> <A title=delphi@delphi.org.nz
href="mailto:delphi@delphi.org.nz">NZ Borland Developers Group - Delphi List</A>
</DIV>
<DIV><B>Subject:</B> Re: [DUG] Email/SMTP code</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<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-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0cm; PADDING-LEFT: 0cm; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<P class=MsoNormal><B><SPAN
style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt"
lang=EN-US>From:</SPAN></B><SPAN
style="FONT-FAMILY: 'Tahoma','sans-serif'; FONT-SIZE: 10pt" lang=EN-US>
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-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">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-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt"> <o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">-Indy10.2.3<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">-Send
attachment<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">-SMTP
server and email addresses will be known<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt"> <o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">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-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt"> <o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt">John<o:p></o:p></SPAN></P></DIV>
<DIV>
<P class=MsoNormal><SPAN
style="FONT-FAMILY: 'Arial','sans-serif'; COLOR: black; FONT-SIZE: 10pt"> <o:p></o:p></SPAN></P></DIV></DIV></DIV></DIV>
<P>
<HR>
_______________________________________________<BR>NZ Borland Developers Group -
Delphi mailing list<BR>Post: delphi@delphi.org.nz<BR>Admin:
http://delphi.org.nz/mailman/listinfo/delphi<BR>Unsubscribe: send an email to
delphi-request@delphi.org.nz with Subject:
unsubscribe</DIV></DIV></DIV></BODY></HTML>