SendEmail using Gmail
Hi guys, i need your help, i from Brazil, i'm trying to use SendEmail with Gmail, but i cann't. I tried to using two ways,
(I've tried everything, I don't know what else to do)
The simple way
procedure Test;
begin
if SendMail('testcompletesuprema@gmail.com', 'smtp.gmail.com', 'João Saidel', 'jp2822@gmail.com', 'Notification', 'Hello Clare, Your application is nice.', 'C:\File1.txt', 'C:\File1.txt') then
Log.Message('Mail was sent')
else
Log.Warning('Mail was not sent');
end;
and
function SendEmail(mFrom, mTo, mSubject, mBody, mAttach);
var i, schema, mConfig, mMessage;
begin
try
schema := 'http://schemas.microsoft.com/cdo/configuration/';
mConfig := Sys.OleObject('CDO.Configuration');
mConfig.Fields.Item(schema + 'sendusing') := 2; // cdoSendUsingPort
mConfig.Fields.Item(schema + 'smtpusessl') := true; // Use SSL
mConfig.Fields.Item(schema + 'smtpserver') := '"smtp.gmail.com';
mConfig.Fields.Item(schema + 'smtpserverport') := 465;
mConfig.Fields.Item(schema + 'smtpauthenticate') := 1; // Authentication mechanism
mConfig.Fields.Item(schema + 'sendusername') := 'testcompletesuprema@gmail.com'; // User name (if needed)
mConfig.Fields.Item(schema + 'sendpassword') := ******; // User password (if needed)
mConfig.Fields.Item(schema + 'smtpconnectiontimeout') := 60; // User password (if needed)
mConfig.Fields.Update;
mMessage := Sys.OleObject('CDO.Message');
mMessage.Configuration := mConfig;
mMessage.From := mFrom;
mMessage.To := mTo;
mMessage.Subject := mSubject;
mMessage.HTMLBody := mBody;
aqString.ListSeparator := ',';
for i := 0 to aqString.GetListLength(mAttach) - 1 do
mMessage.AddAttachment(aqString.GetListItem(mAttach, i));
mMessage.Send;
//Log.Message('Message to <' + mTo + '> was successfully sent');
//Result := True;
//except
//Log.Error('Email cannot be sent', ExceptionMessag);
//Result := False;
// end;
end;
procedure MainTest;
begin
if SendEmail('testcompletesuprema@gmail.com', 'jp29822@gmail.com', 'Subject',
'Message body', 'c:\File1.txt') then
log.Message(' Message was sent')
else
Log.Warning('Message was not sent');
end;