I seriously doubt that TIdSMTP
is sending a ix5msxxx.36 -gsmtp
command. It looks more like a possible data corruption issue, as if the SSL layer is not sending the right data. You can attach a TIdLog...
component, such as TIdLogEvent
, to the TIdSMTP.Intercept
property to verify that TIdSMTP
is actually sending valid SMTP commands and receiving valid SMTP replies.
Other than that, I don't see anything wrong with your code that could cause such a problem. IT could use some cleanup, though:
try
IdMessage1 := nil;
IdSSLIOHandlerSocketOpenSSL1 := nil;
IdSMTP1 := nil;
try
//setup mail message
try
IdMessage1 := TIdMessage.Create(nil);
IdMessage1.From.Address := 'XXX@gmail.com'; // change to their email
IdMessage1.Recipients.EMailAddresses := 'yyy@gmail.com';
IdMessage1.Subject := 'hello';
IdMessage1.Body.Text := 'hello again';
if FileExists(datafilename) then
IdAttachmentFile := TIdAttachmentFile.Create(IdMessage1.MessageParts, datafilename);
except
Exception.RaiseOuterException(Exception.Create('Could not create message, please try again later'));
end;
//setup TLS
try
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlersocketopenSSL.Create(nil);
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmUnassigned;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode := [];
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 0;
except
Exception.RaiseOuterException(Exception.Create('Could not create SSL handler, please try again later'));
end; // of try ssl
//setup SMTP
try
IdSMTP1 := TIdSMTP.Create(nil);
IdSMTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdSMTP1.UseTLS := utUseExplicitTLS;
IdSMTP1.Host := 'smtp.gmail.com';
IdSMTP1.Port := 587;
IdSMTP1.Username := 'xxx@gmail.com';
IdSMTP1.password := 'password';
except
Exception.RaiseOuterException(Exception.Create('Could not create SMTP handler, please try again later'));
end; // of try
try
IdSMTP1.Connect;
try
IdSMTP1.Send(IdMessage1) ;
finally
IdSMTP1.Disconnect;
end;
except
Exception.RaiseOuterException(Exception.Create('Could not send secure email, please try again later'));
end;
finally
IdSMTP1.Free;
IdSSLIOHandlerSocketOpenSSL1.Free;
IdMessage1.Free;
end;
except
on E: Exception do
begin
if E.InnerException <> nil then
ShowMessage('ERROR: ' + E.Message + #13#13 + E.InnerException.Message)
else
ShowMessage('ERROR: ' + E.Message);
end;
end;