Jeg bruger Indy 10 (10.5.8.0) og Delphi 7
Husk de 2 OpenSSL dll filer, de er med i zip filen jeg henviser til.
Jeg har samlet alle filer her:
www.kroning.dk/SSLmailtest.zip-------------
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdException, IdExplicitTLSClientServerBase, IdSMTP, IdMessage, IdSSLOpenSSL;
type
TForm1 = class(TForm)
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
IdSMTP: TIdSMTP;
IdMessage: TIdMessage;
IdSSLIOHandlerSocketOpenSSL: TIdSSLIOHandlerSocketOpenSSL;
const
BenytSSL : boolean = true;
begin
IdSMTP:=TIdSMTP.Create(nil);
IdMessage:=TIdMessage.Create;
IdSSLIOHandlerSocketOpenSSL:=TIdSSLIOHandlerSocketOpenSSL.Create;
if BenytSSL then
begin
IdSMTP.Username:='DIN GMAIL KONTONAVN HER'; //RET HER
IdSMTP.Password:='DIN GMAIL PASSWORD HER'; //RET HER
end;
IdMessage.ContentType:='text/html; charset=utf-8';
IdMessage.Encoding:=meDefault;
IdMessage.Recipients.Add.Address:='MODTAGER MAIL ADRESSE'; //RET HER
IdMessage.Body.Text:='Og teksten i mailen her';
IdMessage.From.Address:='AFSENDER MAIL ADRESSE'; //RET HER
IdMessage.From.Name:='Anders And';
IdMessage.From.Text:=IdMessage.From.Name+' <'+IdMessage.From.Address+'>';
IdMessage.Sender.Address:=IdMessage.From.Address;
IdMessage.Sender.Name:=IdMessage.From.Name;
IdMessage.Sender.Text:=IdMessage.From.Text;
IdMessage.Subject:='En SSL mail test';
IdSMTP.ConnectTimeout:=5000;
if BenytSSL then
begin
IdSMTP.IOHandler:=IdSSLIOHandlerSocketOpenSSL;
IdSMTP.UseTLS:=utUseRequireTLS;
end;
IdSMTP.Host:='smtp.gmail.com';
IdSMTP.Port:=587;
try
IdSMTP.Connect;
IdSMTP.Send(IdMessage);
IdSMTP.Disconnect;
ShowMessage('Mail sendt');
except
on E:Exception do
begin
if not (E is EIdConnClosedGracefully) then
ShowMessage(E.Message);
end;
end;
IdMessage.Free;
IdSMTP.Free;
IdSSLIOHandlerSocketOpenSSL.Free;
end;
end.