Forum Discussion

Andrea_Bonacchi's avatar
Andrea_Bonacchi
New Contributor
4 years ago

Sending e-mail via CDO due to "Transport failed to connect to the server"

Hi everybody,

 

with the help of the on-line documentation I wrote the following code to send an e-mail using CDO.

 

function SendEmail(mFrom, mTo, mSubject, mBody)
{
var schema, mConfig, mMessage;

try
{
schema = "http://schemas.microsoft.com/cdo/configuration/";

 

mConfig = getActiveXObject("CDO.Configuration");


mConfig.Fields.$set("Item", schema + "sendusing", 2); // cdoSendUsingPort
mConfig.Fields.$set("Item", schema + "smtpusessl", 1); // Use SSL
mConfig.Fields.$set("Item", schema + "smtpserver", "smtp.gmail.com"); // SMTP server
mConfig.Fields.$set("Item", schema + "smtpserverport", 465); // Port number (tried to use 587 and 25 port)
mConfig.Fields.$set("Item", schema + "smtpconnectiontimeout", 180); // Port number (I think 180 are seconds)

mConfig.Fields.$set("Item", schema + "smtpauthenticate", 1); // Authentication mechanism

mConfig.Fields.$set("Item", schema + "sendusername", mFrom);

mConfig.Fields.$set("Item", schema + "sendpassword", "<myPassword>");

 

mConfig.Fields.Update();

 

mMessage = getActiveXObject("CDO.Message");
mMessage.Configuration = mConfig;
mMessage.From = mFrom;
mMessage.To = mTo;
mMessage.Subject = mSubject;
mMessage.HTMLBody = mBody;

 

// no attachment

//aqString.ListSeparator = ",";
//for(let i = 0; i < aqString.GetListLength(mAttach); i++)
// mMessage.AddAttachment(aqString.GetListItem(mAttach, i));

 

mMessage.Send();
}
catch (exception)
{
Log.Error("Email cannot be sent", exception.message);
return false;
}
Log.Message("Message to <" + mTo + "> was successfully sent");
return true;
}

 

When the send command is executed, an exception is thrown. The message written in the exception is: "The transport failed to connect to the server".

The mFrom address is a gmail address and for this address has been enabled that less secure apps can access.

 

I read also this post https://community.smartbear.com/t5/TestComplete-Functional-Web/SendMail-not-working-Tried-everything-I-found-in-documentation/td-p/182944/page/2

 

No solutions have been found. The port (465) isn't block by workstation or IT firewall because I can access to my gmail.

 

Any suggestions or help?

 

 

Thank you very much,

Andrea

 

 


  • The port (465) isn't block by workstation or IT firewall because I can access to my gmail.


    Are you sure that port isn't blocked by the firewall? If you can access your gmail you're likely accessing it over the web UI which doesn't use that port.

     

    Are you able to telnet to smtp.gmail.com from your machine using the command line?

  • tphillips's avatar
    tphillips
    Frequent Contributor

    The port (465) isn't block by workstation or IT firewall because I can access to my gmail.


    Are you sure that port isn't blocked by the firewall? If you can access your gmail you're likely accessing it over the web UI which doesn't use that port.

     

    Are you able to telnet to smtp.gmail.com from your machine using the command line?

    • Andrea_Bonacchi's avatar
      Andrea_Bonacchi
      New Contributor

      Hi tphillips,

       

      you are right. On my workstation, trying a telnet connection to google smtp server using the ports 25 and 465 the connection cannot be established.

      I advised my IT.

       

       

      Thanks a lot,

       

      Andrea