(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