Skip to content

Instantly share code, notes, and snippets.

@martinusso
Last active August 29, 2015 14:22
Show Gist options
  • Save martinusso/1308e84dd735edafda09 to your computer and use it in GitHub Desktop.
Save martinusso/1308e84dd735edafda09 to your computer and use it in GitHub Desktop.
Send mail using SMTP Aws-SES
procedure Aws_SES_SendMailUsingSMTP;
var
Username: string;
Password: string;
Host: string;
Port: Integer;
SmtpClient: TIdSMTP;
Msg: TIdMessage;
IdSSL: TIdSSLIOHandlerSocketOpenSSL;
begin
Username := 'USERNAME HERE!!!';
Password := 'PASSWORD HERE!!!';
Host := 'email-smtp.us-west-2.amazonaws.com';
Port := 25;
SmtpClient := TIdSMTP.Create(nil);
try
SmtpClient.Disconnect;
SmtpClient.Host := Host;
SmtpClient.Port := Port;
SmtpClient.Username:= Username;
SmtpClient.Password:= Password;
IdSSL := nil;
try
IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
SmtpClient.IOHandler := IdSSL;
SmtpClient.UseTLS := utUseImplicitTLS;
except
on E: Exception do
begin
SmtpClient.IOHandler := TIdIOHandler.MakeDefaultIOHandler(nil);
SmtpClient.UseTLS := utNoTLSSupport;
end;
end;
if Assigned(IdSSL) then
begin
IdSSL.SSLOptions.Method := sslvSSLv3;
IdSSL.SSLOptions.Mode := sslmClient;
end;
Msg := TIdMessage.Create(nil);
try
Msg.From.Address := '[email protected]';
Msg.Recipients.EMailAddresses := '[email protected]';
Msg.Subject := 'testing Amazon SES';
Msg.Body.Text := 'content of testing Amazon SES';
SmtpClient.Connect;
SmtpClient.Send(Msg);
SmtpClient.Disconnect;
finally
Msg.Free;
end;
finally
SmtpClient.Free;
end;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment