Note that there are some explanatory texts on larger screens.

plurals
  1. POSMTP.host variable issue
    text
    copied!<p>Here is my Issue. I'm using Delphi 5 and Indy 9. I have no option to upgrade either at the moment. I am trying to send an email via gmail, and i hard code the string as 'smtp.google.com' it works just fine. however, if smtp.host is getting the host name from a variable it fails with error 11001, and i havent been able to figure out why. I'm new using indy so i'm probably missing something silly, but i don't understand why it could accept a string as the host, but not a variable holding the string. (It's got to be a variable because i need to pass the procedure different SMTP hosts based on the user signed in. Here is the code:</p> <pre><code>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; //&lt;--FAILS SMTP.Host := 'smtp.google.com'; //&lt;--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; </code></pre> <p>I marked the one that fails and the one that succeeds, but i don't understand what i'm doing wrong. Any help would be appreciated</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload