Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Gmail send plain emails SSL


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Nov 27, 2017 10:42 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
Roberto Rovida

Posts: 2
Registered: 7/27/17
Gmail send plain emails SSL  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2017 4:18 AM
Hello all.
I need to send a plain text email through a Gmail account, without disrupting security features like "Allow less secure apps".
SSL connection is required (port 587).
I'm using Indy for Delphi Tokyo.
Following the Marco Cant├╣ example at http://www.marcocantu.com/tips/oct06_gmail.html.

The TIdSMTP component connects properly, involving the SASL components and a TIdUserPassProvider.
The problem arises when sending an email: I always get a "Username and Password not accepted. Learn more at
https://support.google.com/mail/?p=BadCredentials r14sm13784121wra.71 - gsmtp" error.
I've already generated an application password using the Google functionality, and then used the new username and password for login.
Once again, the TIdSMTP connects without any problem, but sending a mail causes the same error.
What do I do wrong?

Connection objects are:
object IdSMTP1Cantu: TIdSMTP
OnStatus = IdSMTP1CantuStatus
IOHandler = IdSSLIOHandlerSocketOpenSSLCantu
Host = 'smtp.gmail.com'
Password = the password generated by Google for the application
Port = 587
SASLMechanisms = <>
UseTLS = utUseExplicitTLS
Username = the application title as set in Project/Options/Application/Appearance/Application settings
end
object IdSSLIOHandlerSocketOpenSSLCantu: TIdSSLIOHandlerSocketOpenSSL
Destination = 'smtp.gmail.com:587'
Host = 'smtp.gmail.com'
MaxLineAction = maException
Port = 587
DefaultPort = 0
SSLOptions.Mode = sslmUnassigned
SSLOptions.VerifyMode = []
SSLOptions.VerifyDepth = 0
OnStatusInfo = IdSSLIOHandlerSocketOpenSSLCantuStatusInfo
end
object IdUserPassProvider1: TIdUserPassProvider
Username = the application title as set in Project/Options/Application/Appearance/Application settings
Password = the password generated by Google for the application
end

The sending code follows:
try
lstCantu.Items.Add('-- connect');
IdSMTP1Cantu.Connect;
lstCantu.Items.Add('-- send');
IdSMTP1Cantu.Send(olMessage);
finally
lstCantu.Items.Add('-- disconnect');
IdSMTP1Cantu.Disconnect;
end;

Status messages are:
-- connect
IdSMTP1CantuStatus: Connected.
-- send
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "before/connect initialization"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "before/connect initialization"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 write client hello A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read server hello A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read server certificate A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read server key exchange A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read server done A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 write client key exchange A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 write change cipher spec A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 write finished A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 flush data"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read server session ticket A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSLv3 read finished A"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSL negotiation finished successfully"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: SSL status: "SSL negotiation finished successfully"
IdSSLIOHandlerSocketOpenSSLCantuStatusInfo: Cipher: name = ECDHE-RSA-AES128-SHA; description = ECDHE-RSA-AES128-SHA SSLv3 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA1
; bits = 128; version = TLSv1/SSLv3;
-- disconnect
IdSMTP1CantuStatus: Disconnecting.
IdSMTP1CantuStatus: Disconnected.
***** Username and Password not accepted. Learn more at
https://support.google.com/mail/?p=BadCredentials 69sm5016084wmp.37 - gsmtp
Roberto Rovida

Posts: 2
Registered: 7/27/17
Re: Gmail send plain emails SSL  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 23, 2017 5:29 AM   in response to: Roberto Rovida in response to: Roberto Rovida
Solved: username must be the sender's email address and the password must be the one generated by Google.
Remy Lebeau (Te...


Posts: 8,950
Registered: 12/23/01
Re: Gmail send plain emails SSL  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 27, 2017 10:42 AM   in response to: Roberto Rovida in response to: Roberto Rovida
Roberto Rovida wrote:

Solved: username must be the sender's email address and the password
must be the one generated by Google.

Correct. Indy does not implement OAuth yet, so if you do not enable
"Allow less secure apps" then you must generate an app-specific
password instead.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02