I'm trying to send an email using Indy 10 on Delphi 5, what happens is that it doesn't want to authenticate as it shows me the "Nooo" message. So far I have this code here (which I got from another Stack Overflow question). I'm not sure why it doesn't work for me since it apparently did for the other person... Maybe I missed something, I replaced the senderemail and receiveremail with 2 of my actual mails and the password of course.
EDIT
So that's where I am right now, it pops a "Must issue a STARTTLS command first." error now however... I'm really confused with this...
EDIT 2
So I managed to make it work, here's the final result. Feel free to tell me if something isn't done properly... I had an Access Violation until I added the "IdSMTP.Authenticate;" line before sending the message!
procedure TForm1.Button3Click(Sender: TObject);
var
IdSMTP: TIdSMTP;
Email: TIdMessage;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
begin
IdSMTP := TIdSMTP.Create(nil);
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
Email := TIdMessage.Create(nil);
try
SSLHandler.MaxLineAction := maException;
SSLHandler.SSLOptions.Method := sslvSSLv23;
SSLHandler.SSLOptions.Mode := sslmUnassigned;
SSLHandler.SSLOptions.VerifyMode := [];
SSLHandler.SSLOptions.VerifyDepth := 0;
IdSMTP.IOHandler := SSLHandler;
IdSMTP.Host := 'smtp.gmail.com';
IdSMTP.Port := 587;
IdSMTP.Username := '[email protected]';
IdSMTP.Password := 'password';
IdSMTP.UseTLS := utUseExplicitTLS;
Email.From.Address := '[email protected]';
Email.Recipients.EmailAddresses := '[email protected]';
Email.Subject := 'Test subject';
Email.Body.Text := 'Test body';
IdSMTP.Connect;
if IdSMTP.Connected then
begin
IdSMTP.Authenticate;
IdSMTP.Send(Email);
IdSMTP.Disconnect;
end;
finally
Email.Free;
SSLHandler.Free;
IdSMTP.Free;
end;
end;
AuthType=satDefault
does not work with all servers. It uses theAUTH LOGIN
command, which is not secure, and some servers have dropped support for it. You should consider usingAuthType=satSASL
with theTIdSMTP.SASLMechanisms
collection instead. You do not need to call Authenticate() manually – Roman Marusyk