Gmail SMTP: Send with an App Password on Port 587
See more SMTP Examples
Send through Gmail on port 587 using required STARTTLS and an app password. This page replaces the former less-secure password-authentication instructions. Port 465 uses implicit TLS instead.
This sends a real email. Use a recipient you control and the account's authorized sender identity. Gmail sending limits still apply. For OAuth2, use the token-based sending example.
Use an account-specific app password generated after enabling 2-Step Verification, loaded from protected configuration. A normal Google password will not work. App passwords may be unavailable under account or Workspace policy; OAuth2 is preferred. Changing the Google account password revokes app passwords. The obsolete less-secure-apps switch is not a setup option. Google app-password requirements.
See the Gmail SMTP, IMAP, and POP3 guide for current authentication choices and Gmail-specific examples.
Chilkat Lazarus Pascal Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.MailMan,
Chilkat.Email;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
mailbox: string;
mailman: TMailMan;
email: TEmail;
begin
success := False;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
mailbox := 'user@example.com';
mailman := TMailMan.Create;
mailman.SmtpHost := 'smtp.gmail.com';
mailman.SmtpPort := 587;
mailman.SmtpSsl := False;
mailman.StartTLS := True;
mailman.RequireSslCertVerify := True;
// Alternative: port 465 with SmtpSsl=true and StartTLS=false (implicit TLS).
mailman.SmtpUsername := mailbox;
// Load the app password from protected configuration.
mailman.SmtpPassword := 'YOUR_16_CHARACTER_APP_PASSWORD';
email := TEmail.Create;
email.From := mailbox;
email.Subject := 'Sample message';
email.Body := 'This message was sent through Gmail SMTP using an app password.';
success := email.AddTo('Recipient','recipient@example.net');
if (success <> True) then
begin
WriteLn('Could not add the recipient.');
Exit;
end;
// This sends a real message. Replace the recipient with an address you control.
success := mailman.SendEmail(email);
if (success <> True) then
begin
mailman.CloseSmtpConnection();
WriteLn('SMTP send failed. Check the app password, mailbox, recipient, and Gmail sending limits.');
// Inspect LastErrorText privately if needed; do not publish authentication/session logs.
// A lost connection after DATA can leave acceptance uncertain. Avoid blindly retrying.
Exit;
end;
success := mailman.CloseSmtpConnection();
if (success <> True) then
begin
WriteLn('Gmail accepted the message, but closing the connection failed. Do not resend it.');
Exit;
end;
WriteLn('Gmail accepted the message for delivery.');
mailman.Free;
email.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.