Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending email through Gmail
#1
Hello,

I am using Indy10 on C++Builder 6.0 Professional Edition, which I have already succeeded on sent an email using Gmail some time ago.

Now I have to do it again and it seems that no matter the settings I have choosen  to TIdSMTP or TIdSSLIOHandlerSocketOpenSSL, I've been getting the same server answer: "You must issue a STARTTLS first".

I am using Port = 587 and TLS support.

Which are the correct settings to enable Indy10 to send emails using Gmail's SMTP?

Thank you very much.

Jayme Jeffman Filho.
Reply
#2
(07-16-2018, 08:19 PM)jjeffman Wrote: Which are the correct settings to enable Indy10 to send emails using Gmail's SMTP?

You need to connect to 'smtp.gmail.com' on port 587, and have the UseTLS property set to utUseExplicitlTLS (be aware that the UseTLS setter can change the Port property, so make sure you are actually connecting to the correct port!).

Also, Indy does not yet support OAuth authentication over SASL, so if you have multi-factor authentication enabled in your Gmail account, you need to generate an application-specific password in your Gmail security settings, and then you can use that password with Indy, using your gmail email address as the username.

Reply
#3
(07-16-2018, 09:21 PM)rlebeau Wrote:
(07-16-2018, 08:19 PM)jjeffman Wrote: Which are the correct settings to enable Indy10 to send emails using Gmail's SMTP?

You need to connect to 'smtp.gmail.com' on port 587, and have the UseTLS property set to utUseExplicitlTLS (be aware that the UseTLS setter can change the Port property, so make sure you are actually connecting to the correct port!).

Also, Indy does not yet support OAuth authentication over SASL, so if you have multi-factor authentication enabled in your Gmail account, you need to generate an application-specific password in your Gmail security settings, and then you can use that password with Indy, using your gmail email address as the username.

Thank you very much for answering me.

I have checked the sender gmail account and it does not require a two steps login procedure.

Code:
   emailStatus->Lines->Add("About to connect using:");
   emailStatus->Lines->Add("username: " + SMTP->emailSender->Username);
   emailStatus->Lines->Add("password: " + SMTP->emailSender->Password);
   emailStatus->Lines->Add("SMTP: " + SMTP->emailSender->Host);
   emailStatus->Lines->Add("Porta: " + IntToStr(SMTP->emailSender->Port) );
   emailStatus->Lines->Add("UseTLS: "+ SMTP->GetTLSMode() );
   emailStatus->Lines->Add("TLSMethod: "+SMTP->GetTLSMethod());

   //send mail
   try{
     //SMTP->emailSender->ConnectTimeout = 120;
     SMTP->emailSender->Connect();
     SMTP->emailSender->Send(SMTP->emailMessage);
   }
   catch( Exception *E){
     emailStatus->Lines->Add( "ERROR: " + E->Message);
   }



The code above add the lines below to a TMemo :


Quote:Indy10 version: 10.6.2.0
Sending email to: me@gmail.com
About to connect using:
username: <recipient>@gmail.com
password: ********
SMTP: smtp.gmail.com
Porta: 587
UseTLS: utNoTLSSupport
TLSMethod: sslvTLSv1
Resolving hostname smtp.gmail.com.

Connecting to 64.233.190.108.

Connected.
SMTP Connected
ERROR: Must issue a STARTTLS command first. 49-v6sm947685qtu.0 - gsmtp

Disconnecting.
SMTP Disconnected
Disconnected.


No matter the value I set to the SSLOptions method the error message is the same. All the dll modules has been loaded unless I have called the function outside the correct position.

I have just changed some code positions to assure that Port and UseTLS properties have the correct value. The error has changed to :

"ERROR: <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt6
0p_wj6E9KhbWDRIYTXL6YEbKe0N7DiH8CI74CO8P28UObvXknuYgd6NLLXi_gK3bQPRPfw
W4cJSXeqRDmmdao9yKEJToJLJwJRM7cWz0hSwRg_SkhnI-IR2IB38QqvEfzcHvOHD-HnT4
9IXPaGnyUCffpeTawZ5DQhBatcB45l1Ncta9mWLrg-02ePGMdFyVnwNWV8U1EPlOYUZ3C0
rY3Dizvx9JK2UC-zyHlRi9VYUyUdD84xr6LeX1qRzZDjbFHtyi> Please log in via
your web browser and then try again."

What am I doing wrong?

After going to the limk Gmail sent in the error message and having changed the security options I have succeeded on snding emails through Gmail SMTP.

Thank you very much.

Best regards.

Jayme Jeffman
Reply
#4
(07-17-2018, 03:05 PM)jjeffman Wrote:
Quote:SMTP: smtp.gmail.com
Porta: 587
UseTLS: utNoTLSSupport

You MUST set UseTLS to utUseExplicitTLS when using port 587. That will send the required STARTTLS command.

(07-17-2018, 03:05 PM)jjeffman Wrote: No matter the value I set to the SSLOptions method the error message is the same.

Because the STARTTLS error has nothing to do with the SSL/TLS settings themselves. STARTTLS is an SMTP command to request a SSL/TLS session be created on a currently-unsecure connection.

(07-17-2018, 03:05 PM)jjeffman Wrote: I have just changed some code positions to assure that Port and UseTLS properties have the correct value. The error has changed to :

"ERROR: <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbt6
0p_wj6E9KhbWDRIYTXL6YEbKe0N7DiH8CI74CO8P28UObvXknuYgd6NLLXi_gK3bQPRPfw
W4cJSXeqRDmmdao9yKEJToJLJwJRM7cWz0hSwRg_SkhnI-IR2IB38QqvEfzcHvOHD-HnT4
9IXPaGnyUCffpeTawZ5DQhBatcB45l1Ncta9mWLrg-02ePGMdFyVnwNWV8U1EPlOYUZ3C0
rY3Dizvx9JK2UC-zyHlRi9VYUyUdD84xr6LeX1qRzZDjbFHtyi> Please log in via
your web browser and then try again."

What am I doing wrong?

Nothing. Google is simply asking you to verify your PC/device before it will then allow an SMTP session from that same PC/device.

(07-17-2018, 03:05 PM)jjeffman Wrote: After going to the limk Gmail sent in the error message and having changed the security options I have succeeded on snding emails through Gmail SMTP.

OK.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)