Delphi

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Want to access default mail client

    7 answers - 368 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I've never done any mail stuff before and want to get started; maybe read an article
    I need to throw up an email using the default mail client after filling in a couple of fields so
    that the user can enter a message or modify the subject line or whatever.
    TIA
    Wayne Roser
    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.1 | | 1510 bytes | |

    You can find info by searching around the delphi.about.com site, but here's
    something to get you started:

    procedure TForm1.btnEmailClick(Sender: T);
    var
    em_subject, em_body, em_mail: string; //em_mail is the whole mail message;
    em_subject & em_body are
    //the subject
    line and message body
    begin
    em_subject := 'Message Subject Line Here';
    em_body := 'Text of e-mail message goes here';
    em_mail := 'mailto:name (AT) isp (DOT) com?subject=' + em_subject + '&body=' +
    em_body;
    //convert Delphi's carriage returns to a version email programs like
    Express understand:
    em_mail:=StringReplace(em_mail,#13#10,'%0D%0A',[rfReplaceAll]);
    ShellExecute(Handle, 'open', PChar(em_mail), nil, nil, SW_SHWNRMAL);
    end;

    Hope this helps. -- Al C.

    Message
    From: "Wayne Roser" <rr (AT) kristin (DOT) school.nz>
    To: <delphi (AT) elists (DOT) org>
    Sent: Monday, 31, 2005 11:49 AM
    Subject: Want to access default mail client

    I've never done any mail stuff before and want to get started; maybe read
    an article

    I need to throw up an email using the default mail client after filling in
    a couple of fields so
    that the user can enter a message or modify the subject line or whatever.

    TIA
    Wayne Roser

    Delphi mailing list -Delphi (AT) elists (DOT) org

    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.2 | | 2754 bytes | |

    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

    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 -Delphi (AT) elists (DOT) org
  • No.3 | | 3813 bytes | |

    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'll look around and learn some
    more, 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.

    Message
    From: "Rainer von Saleski" <rainer (AT) vonsaleski (DOT) com>
    To: "Borland's Delphi Discussion List" <delphi (AT) elists (DOT) org>
    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

    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 -Delphi (AT) elists (DOT) org

    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.4 | | 5780 bytes | |

    Hi,

    You might want to try reading some of the source files; they're provided (at
    least with my copy of Delphi). BrowseSymbol can often get you there.

    atLogin and atNone are symbolic constants, and have to be one value or the
    other. Choose according to whether or not your server requires
    authentication (mine all do). If you specify atLogin, then you need the
    UserName and PassWord fields (specify the appropriate string constants for
    your account on your server).

    Message
    From: "Alan Colburn" <aicolburn (AT) hotmail (DOT) com>
    To: "Borland's Delphi Discussion List" <delphi (AT) elists (DOT) org>
    Sent: Friday, November 04, 2005 12:43 PM
    Subject: Re: Want to access default mail client

    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'll look around and learn
    some more, 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.

    Message
    From: "Rainer von Saleski" <rainer (AT) vonsaleski (DOT) com>
    To: "Borland's Delphi Discussion List" <delphi (AT) elists (DOT) org>
    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
    >
    >>

    >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 -Delphi (AT) elists (DOT) org
    >
    >>

    >


    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.5 | | 677 bytes | |

    Hi all --
    I'm trying to make an e-mail client. Thanks to Rainer, and others on this
    list, I've got a better sense of authentication. Some servers require
    authentication, others do not. I guess this is something often dealt with as
    a user setting setting up an e-mail program, the user enters whether
    or not the server requires authentication.

    Is there any way around this? Is there a way to code that says, essentially,
    'if the server requires authentication then AuthenticationType:=atLogin else
    AuthenticationType:=atNone'?

    Thanks, in advance -- Al

    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.6 | | 1483 bytes | |

    The user must provide that nugget of information. way to do it would be
    to put a checkbox on the screen that says "Use Authentication", and set the
    action accordingly. This should be straightforward Delphi.

    Rainer

    To get you started

    if UseAuthenticationBox.Checked then begin
    SMTP.AuthenticationType := atLogin;
    SMTP.Username := UserNameEdit.text;
    SMTP.Password := PasswordEdit.text;
    end else begin
    SMTP.AuthenticationType := atNone;
    end;

    Message
    From: "Alan Colburn" <aicolburn (AT) hotmail (DOT) com>
    To: "Borland's Delphi Discussion List" <delphi (AT) elists (DOT) org>
    Sent: Friday, November 11, 2005 4:53 PM
    Subject: Re: Mail Clients & Authentication

    Hi all --

    I'm trying to make an e-mail client. Thanks to Rainer, and others on this
    list, I've got a better sense of authentication. Some servers require
    authentication, others do not. I guess this is something often dealt with
    as a user setting setting up an e-mail program, the user enters
    whether or not the server requires authentication.

    Is there any way around this? Is there a way to code that says,
    essentially, 'if the server requires authentication then
    AuthenticationType:=atLogin else AuthenticationType:=atNone'?

    Thanks, in advance -- Al
    >
    >
    >


    Delphi mailing list -Delphi (AT) elists (DOT) org
  • No.7 | | 1399 bytes | |

    I'm trying to make an e-mail client. Thanks to Rainer, and others on this
    list, I've got a better sense of authentication. Some servers require
    authentication, others do not. I guess this is something often dealt with
    as
    a user setting setting up an e-mail program, the user enters whether
    or not the server requires authentication.

    Is there any way around this? Is there a way to code that says,
    essentially,
    'if the server requires authentication then AuthenticationType:=atLogin
    else
    AuthenticationType:=atNone'?

    ICS SMTP component has an auto mode. You set AuthType := smtpAuthAutoSelect
    and the component use the authentication method according to what the SMTP
    server reply to the EHL command which is supposed to return supported
    server extensions.

    So you should send EHL command instead of HEL command. If the server
    doesn't understand it (it returns an error or disconnect), it is much likely
    that it doesn't support authentication anyway. If it support the EHL
    command then the reply _may_ contain the authentication mode supported by
    the server.

    You probably already know that ICS components are available as freeware with
    source code from http://www.overbyte.be (and also on you Delphi companion
    CD, but al older version of course).

    Contribute to the SSL Effort. Visit

Re: Want to access default mail client


max 4000 letters.
Your nickname that display:
In order to stop the spam: 0 + 9 =
QUESTION ON "Delphi"

EMSDN.COM