MarshallSoft

Delphi Email Example


unit example;

interface

uses
 see32,
 SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics,
 Controls, Forms, Dialogs, Menus, StdCtrls;

function SendMail(ToList,Subject,Message: String):Integer;

implementation

{connect to SMTP server then send email}

function SendMail(ToList,Subject,Message: String):Integer;
var
  Code : Integer;
  SmtpHost : AnsiAnsiString;
  SmtpUser : AnsiString;
  SmtpPass : AnsiString;
  SmtpFrom : AnsiString;
  SmtpReply : AnsiString;
  SmtpTo : AnsiString;
  SmtpSubject : AnsiString;
  SmtpMessage : AnsiString;
  ccList : AnsiString;
  bccList : AnsiString;
  Attachments : AnsiString;
begin
  SmtpHost := 'smtp.my-isp.com';
  SmtpUser := 'my-user-name';
  SmtpPass := 'my-password';
  SmtpFrom := '<mike@my-isp.com>'
  SmtpReply:= '<mike@my-isp.com>'
  ccList := Chr(0);
  bccList := Chr(0);
  Attachments := Chr(0);
  {specify the port to connect on (default port is 25)}
  seeIntegerParam(0, SEE_SMTP_PORT, 587);
  {enable "SMTP Authentication"}
  seeIntegerParam(0, SEE_ENABLE_ESMTP, 1);
  {specify the user name and password for SMTP authentication}
  seeStringParam(0, SEE_SET_USER, @SmtpUser[1]);
  seeStringParam(0, SEE_SET_SECRET, @SmtpPass[1]);
  {connect to SMTP server}
  Code := seeSmtpConnect(0, @SmtpHost[1], @SmtpFrom[1], @SmtpReply[1]);
  if Code < 0 then
  begin
    SendMail := Code;
    exit;
  end;
  {send email to list of recipients}
  SendMail := seeSendEmail(0,@SmtpTo[1],@bccList[1],@ccList[1], @SmtpSubject[1],@SmtpMessage[1],@Attachments[1])
end;

{initialization} begin end.

MSC Logo

HOME PAGE
MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.