0

これが私の問題です。Delphi5とIndy9を使用しています。現時点ではアップグレードするオプションもありません。Gmail経由でメールを送信しようとしていますが、文字列を「smtp.google.com」としてハードコーディングしています。問題なく機能します。ただし、smtp.hostが変数からホスト名を取得している場合は、エラー11001で失敗し、その理由を理解できませんでした。私はindyを初めて使用するので、おそらく何かばかげたものが欠けていますが、なぜ文字列をホストとして受け入れることができるのかわかりませんが、文字列を保持する変数は受け入れられません。(サインインしたユーザーに基づいて異なるSMTPホストのプロシージャを渡す必要があるため、変数にする必要があります。コードは次のとおりです。

procedure TFormEmail.SendSimpleMail(ToEmail, MyAttachment: string);
var
  Msg: TIdMessage;
  DestAddr: TIdEmailAddressItem;
  SMTP: TIdSMTP;
  SSLHandler : TidSSLIOHandlerSocket;
  Attachment: TIdAttachment;
  SMTPHost1 :string;
begin
  Msg := idMessage1;
  Msg.From.Text := EmailName(My_User);
  Msg.From.Address := EmailAddress(My_User);
  msg.Subject := 'Test';//email subject
  DestAddr := Msg.Recipients.Add;
  DestAddr.Text := '';//receiver's name (optional)
  DestAddr.Address := ToEmail;//where its going
  Msg.Body.Add(edtEmailBody.text); //email body
  SMTP := IdSMTP1;
  SMTP.IOHandler := idSSLIOHandlerSocket1;
  SMTPhost1 := SMTPHost(My_User);
  SMTPhost1 := 'smtp.google.com';  
  //SMTP.Host := SMTPhost1;  //<--FAILS
  SMTP.Host := 'smtp.google.com'; //<--SUCCEEDS
  SMTP.Port := SMTPPort(My_User);
  SMTP.AuthenticationType := atLogin; //error here (2 error)
  SMTP.Username := EmailAddress(My_User);
  SMTP.Password := SMTPPassword(My_User);
  If not empty(MyAttachment) then
    Attachment := TIdAttachment.Create(Msg.MessageParts, MyAttachment);//loads Att
  Try
    SMTP.Connect;
  except
    SMTP.Connect;//refire if exception (issue with INDY)
  end;
  if useSSL(My_User) then
    SMTP.SendCmd('STARTTLS');//load TLS 
  SMTP.Authenticate;
  SMTP.Send(Msg);
  SMTP.Disconnect;//disconnect from server
end;

失敗したものと成功したものにマークを付けましたが、何が間違っているのかわかりません。どんな助けでもいただければ幸いです

4

1 に答える 1

0

1つの質問でさらに問題があるようですが、私がお手伝いできるのは1つだけです。

Connectでも同じ問題が発生しました。単に、IdSSLOpenSSLHeadersからLoadメソッドを呼び出しました。

次のことを試してください。

SMTP := IdSMTP1;
IdSSLOpenSSLHeaders.Load;
SMTP.IOHandler := idSSLIOHandlerSocket1;
于 2012-12-13T16:03:05.143 に答える