Send SMTP email with Office365 account

Download Source Code

This sample connects to the host via the STARTTLS command, composes a sample mail message and sends it.

procedure TForm1.btnSendClick(Sender: TObject);
  if (clSmtp1.Active) then Exit;
  clSmtp1.Server := '';
  clSmtp1.Port := 587;
  clSmtp1.UserName := edtUser.Text;
  clSmtp1.Password := edtPassword.Text;
  clSmtp1.UseTLS := ctExplicit;
    clMailMessage1.BuildMessage(memBody.Text, '');
    clMailMessage1.From.FullAddress := edtUser.Text;
    clMailMessage1.ToList.EmailAddresses := edtTo.Text;
    clMailMessage1.Subject := edtSubject.Text;
    ShowMessage('The message was sent successfully.');

Confirm server credentials:

procedure TForm1.clSmtp1VerifyServer(Sender: TObject; ACertificate: TclCertificate; const AStatusText: string;
  AStatusCode: Integer; var AVerified: Boolean);
  if not AVerified and (MessageDlg(AStatusText + #13#10' Do you wish to proceed ?',
    mtWarning, [mbYes, mbNo], 0) = mrYes) then
    AVerified := True;

Article ID: 87, Created On: 2/13/2017, Modified: 3/2/2017