Ask a Question

SendEmail using Gmail

SOLVED
joaosaidel
Occasional Contributor

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;

1 ACCEPTED SOLUTION

Accepted Solutions
7 REPLIES 7
joaosaidel
Occasional Contributor

Re: SendEmail using Gmail

The simple way, i have this erro, '

Socket Error # 10060
Connection timed out.

'

joaosaidel
Occasional Contributor

Re: SendEmail using Gmail

second way, i have this erro, '

CDO.Message.1

Transport connection to server failed

'

 
Marsha_R
Community Hero

Re: SendEmail using Gmail

Are you able to access Gmail manually on the TestComplete machine and send a message to the FromAddress that you are using in the test?

joaosaidel
Occasional Contributor

Re: SendEmail using Gmail

I can't, I'm reviewing sendemail parameters

joaosaidel
Occasional Contributor

Re: SendEmail using Gmail

I managed to send the email. Is there a way to view the logs via email?

sonya_m
Community Manager

Re: SendEmail using Gmail

Thank you for providing the help article, Marsha!

 

Hi @joaosaidel! Did it answer your question? 


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: