Link to home
Start Free TrialLog in
Avatar of rickluttrell
rickluttrell

asked on

Sending EMail via SMTP or MAPI

Never done this before but I'd like to send EMail with attachments from a Delphi7 application. How do I determine if SMTP server is available (get it's address) or if SMTP is not available how to send the email via. the default email program. Any assistance is appreciated.
Avatar of Kristao
Kristao

Hi

Try use Indy commponents

simplest code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdMessageClient, IdSMTP, IdMessage;

type
  TForm1 = class(TForm)
    send_mail: TIdSMTP;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  msg: TIdMessage;
begin
  msg := TIdMessage.Create(self);
  msg.Body.Text := 'This is Test mail';
  msg.From.Address := 'myname@myhost.com';
  msg.Subject := 'Test';
  msg.Recipients.EMailAddresses := 'friend@friendshost.com';
  TIdAttachment.Create(msg.MessageParts, 'C:\myattachemt.jpg');
  send_mail.Send(msg);
  msg.Free;
end;

end.

you can tune it up =) but its the simplest way =)

all you need to know is Host and Port to SMTP server and set it up to commponent in this case send_mail: TIdSMTP;

regards,
kristao.
Avatar of rickluttrell

ASKER


Thank's kristao , but my question was 'How do I determine if SMTP server is available (get it's address)'. Is it derived from the msg.From.Address as listed in you code snip ?
ASKER CERTIFIED SOLUTION
Avatar of Kristao
Kristao

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial