Thursday, 22 August 2013

delphi 6 how to sending email using CDO_TLB

delphi 6 how to sending email using CDO_TLB

i know this is an old topic and i have tried to look at the internet for a
solution. the code is a little straight forward but cannot make it to
work.
i already have the code but delphi 6 gives me a message
"SendUsing" configuration value is invalid
my goal is to send a file attach to my own gmail account.
procedure TForm1.Button1Click(Sender: TObject);
var
M: IMessage;
s: string;
begin
//uses CDO_TLB;
M := CoMessage.Create;
M.From := 'myname@gmail.com';
M.To_ := 'myname@gmail.com';
M.Subject := 'This is subject' + datetimetostr(now);
M.TextBody := 'This is text body' + datetimetostr(now);
s := 'http://schemas.microsoft.com/cdo/configuration/';
with M.Configuration.Fields do begin
Item[s + 'sendusing'].Value := cdoSendUsingPort;
Item[s + 'smtpserver'].Value := 'smtp.gmail.com';
Item[s + 'smtpauthenticate'].Value := cdoBasic ;
Item[s + 'sendusername'].Value := 'myname';
Item[s + 'sendpassword'].Value := 'mypassword';
Item[s + 'smtpserverport'].Value := 465;
Item[s + 'smtpusessl'].Value := False;
Item[s + 'smtpconnectiontimeout'].Value := 5; // default is 30 seconds
Update;
end;
try
M.Send;
// success
except
// fail
on E: Exception do
ShowMessage(E.Message);
end;
end;

1 comment:

  1. I have send mail using CDO (from VBA) to a gmail account, and had to put Item(s + 'smtpusessl') := 1

    ReplyDelete