【发布时间】:2014-02-21 17:32:11
【问题描述】:
我正在使用下面的 gmail 服务器(Delphi XE5 和 Indy,SMTP)代码从应用程序内部发送电子邮件。如果应用程序在 Nexus 7(或 Windows 中的模拟器)上运行,一切都很好。但在 Galaxy S2 上,它引发了一个异常“无法识别的命令 ix5msxxx.36 -gsmtp”
我做错了什么。我一直在寻找这种不规则行为的答案,但没有运气。
try //setup mail message
IdMessage1 := TIdMessage.Create(NIL);
IdMessage1.From.Address := 'XXX@gmail.com'; // change to thier emia
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 Showmessage('Could not create message, please try later');
end; // of try to create an email
try
IdSSLIOHandlerSocketOpenSSL1 := TIdSSLIOHandlersocketopenSSL.Create(NIL);
IdSSLIOHandlerSocketOpenSSL1.Destination := 'smtp.gmail.com:587';
IdSSLIOHandlerSocketOpenSSL1.Host := 'smtp.gmail.com';
IdSSLIOHandlerSocketOpenSSL1.Port := 587;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Method := sslvTLSv1;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.Mode := sslmUnassigned;
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyMode := [];
IdSSLIOHandlerSocketOpenSSL1.SSLOptions.VerifyDepth := 0;
except Showmessage('Could createe SSL handle ');
end; // of try ssl
try
//setup SMTP
IdSMTP1 := TIdSMTP.Create(NIL);
I dSMTP1.Host := 'smtp.gmail.com';
IdSMTP1.Port := 587;
IdSMTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;
IdSMTP1.UseTLS := utUseExplicitTLS;
IdSMTP1.Username := 'xxx@gmail.com';
IdSMTP1.password := 'password';
except Showmessage('Could not send secure email connection, please try later');
end; // of try
try
try
IdSMTP1.Connect;// (1000) ;
IdSMTP1.Send(IdMessage1) ;
except on E:Exception do
showmessage('ERROR: ' + E.Message) ;
end;
finally
if IdSMTP1.Connected then IdSMTP1.Disconnect;
IdSMTP1.Free ;
IdSSLIOHandlerSocketOpenSSL1.Free;
IdMessage1.Free
end;
【问题讨论】: