Hi Ranier -- Thanks for your post here. As it turns out, I'm now just starting to try coding a simple eMail sender, so your post is perfect for me.
Can you help a little with one of the lines of code: SMTP.AuthenticationType := atLogin; My knowledge about SMTP is a little skimpy--I'll look around and learn some more--but, as I understand it, some servers will need authentication and some won't. Can you tell me a little more about how that part of the process works? How would you write the code in a way that would work universally? In addition, I'm a little uncertain about the atLogin variable. Is this something you declared? Is it placeholder text, like 'Email password'? Thanks! -- Al C. ----- Original Message ----- From: "Rainer von Saleski" <[EMAIL PROTECTED]> To: "Borland's Delphi Discussion List" <[email protected]> Sent: Tuesday, November 01, 2005 1:09 PM Subject: Re: Want to access default mail client > There is a very nice Email-sender built into Delphi 7 (it may also be > available in earlier versions) as part of Indy. > > You can find a write-up (with some omissions) at > http://forums.about.com/n/pfx/forum.aspx?msg=8220.1&nav=messages&webtag=ab-delphi > > Here is my wrapper for creating and sending Emails. Just call the > procedures in the order they appear here (as often as necessary). Be sure > to change the text strings in EmailInit to reflect your own email account. > > Rainer > > > [Begin Code] > > unit EmailUnit; > > interface > > uses > inifiles, Windows, Messages, SysUtils, Variants, Classes, Graphics, > Controls, Forms, > Dialogs, IdComponent, IdTCPConnection, IdTCPClient, IdMessageClient, > IdSMTP, ComCtrls, StdCtrls, Buttons, ExtCtrls, > IdBaseComponent, IdMessage, IdEmailAddress; > > type > TEmail = class (TForm) > MailMessage: TIdMessage; > SMTP: TIdSMTP; > end; > > var > Email: TEmail; > procedure EmailInit (FromName, FromAddr, Subject: string; Body: > TStrings); > procedure EmailTo (ToName, ToAddr: string); {May be called more than > once} > procedure EmailAttach (FileName: string); {May be called more than > once} > procedure EmailSend; > > implementation > > {$R *.dfm} > > procedure EmailInit (FromName, FromAddr, Subject: string; Body: TStrings); > begin with Email do begin > > // SMTP Host > SMTP.Host :='Email SMTP Server'; > SMTP.Port := 25; > > // User Name and Password > SMTP.AuthenticationType := atLogin; // or atNone if your host doesn't > casre who you are > SMTP.Username := 'Email User Name'; > SMTP.Password := 'Email Password'; > > // Message Parts > MailMessage.Clear; > MailMessage.From.Name := FromName; > MailMessage.From.Address := FromAddr; > MailMessage.Recipients.Clear; > MailMessage.Subject := Subject; > MailMessage.Body.Text := Body.Text; > end end; > > procedure EmailTo (ToName, ToAddr: string); > var > EI: TIdEMailAddressItem; > begin with Email do begin > EI := MailMessage.Recipients.Add; > EI.Name := ToName; > EI.Address := ToAddr; > end end; > > procedure EmailAttach (FileName: string); > begin with Email do begin > if FileExists(FileName) > then TIdAttachment.Create(MailMessage.MessageParts, FileName) > else ShowMessage (format ('Attachment "%s" not found', [FileName])); > end end; > > procedure EmailSend; > begin with Email do begin > try > try > SMTP.Connect(1000); > SMTP.Send(MailMessage); > except on E:Exception do > ShowMessage ('Email Error: ' + E.Message); > end; > finally > if SMTP.Connected then SMTP.Disconnect; > end; > end end; > > end. > > [End of Code] > > _______________________________________________ > Delphi mailing list -> [email protected] > http://www.elists.org/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list -> [email protected] http://www.elists.org/mailman/listinfo/delphi

