Jump to content
Cartman.

[Delphi] Sending Email With The CDO Message Object

Recommended Posts

Posted

uses the message object of CDO, (Collaboration Data Objects). First set up the fields for your SMTP server, then start building your message to send.

library Project1;
{
By bb69
}
uses
ComObj;

function SendMail(_S, _F, _T, _B, _SR,_U,_PW,_A : WideString ;_P:Integer): Boolean; stdcall;
const
_Cdo='http://schemas.microsoft.com/cdo/configuration/';
var
_Message:OleVariant;
_Config: OleVariant;
begin
//_Config Object
_Message:= CreateOleObject('CDO.Message');
_Config:= CreateOleObject('CDO.Configuration');
//
try
_Config.Fields(_Cdo+'sendusername'):= _U;
_Config.Fields(_Cdo+'sendpassword'):= _PW;
_Config.Fields(_Cdo+'sendusing'):= 2;
_Config.Fields(_Cdo+'smtpserver'):= _SR;
_Config.Fields(_Cdo+'smtpserverport'):= _P;
_Config.Fields(_Cdo+'smtpconnectiontimeout'):= 60;
_Config.Fields(_Cdo+'smtpauthenticate'):= 1;
// _Config.Fields(_Cdo+'urlgetlatestversion'):= ;
_Config.Fields(_Cdo+'smtpusessl'):= True; // use SSL
_Config.Fields.Update;
_Message.Configuration:= _Config;
_Message.To := _T;
_Message.From := _F;
_Message.Subject := _S;
if _A <> '' then
_Message.AddAttachment(_A);
//_Message.HTMLBody := Body; //to send in Html format
// _Message.CreateMHTMLBody('http://www.google.com'); //to send site
_Message.TextBody := _B;
try
_Message.Send;
Result:=True;
Except// on err:Exception do
Result:=False;//err.Message;
end;

finally
VarClear(_Message);
VarClear(_Config);
end;
end;
exports
SendMail;

begin
end.

usage

var
Form1: TForm1;
function SendMail(_S, _F, _T, _B, _SR,_U,_PW,_A : WideString ;_P:Integer): Boolean; stdcall; external 'Project1.dll';
implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
begin if SendMail('test _Cdo', 'from@gmail.com', 'to@gmail.com', 'hellllllllllllllllo', 'smtp.gmail.com','user','password','c:\1.txt',465)then
ShowMessage('ok');
end;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...