Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your code is not setting up <code>TIdMessage</code> correctly when attachments are present. Try this instead:</p> <pre><code>function easySendEmail( theIdSmtp : TIdSmtp; destEMailAddress : string; theSubject : string; theBody : string; emailServerSettings : TEmailServerSettingsRecord; aryAttachmentFilenames : TDynamicStringArray; connectTimeOut_ms : integer; bUseEHLO : boolean; authLoginType : TAuthenticationType): boolean; var IdMsg: TIdMessage; i: integer; begin destEMailAddress := Trim(destEMailAddress); if destEMailAddress = '' then raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The destination E-mail address is empty.'); theSubject := Trim(theSubject); if theSubject = '' then raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The subject line is empty.'); theBody := Trim(theBody); if theBody = '' then raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The message body is empty.'); IdMsg := TIdMessage.Create(nil); try with emailServerSettings do begin // Build a test message and send it. IdMsg.Recipients.EMailAddresses := destEMailAddress; { Most SMTP servers require the sending E-mail address as the user name for the authentication. However, if we encounter one that doesn't work this way then re-using the authentication user name as the From address will not work. } IdMsg.From.Name := APPLICATION_NAME_EVERMAIL; IdMsg.From.Address := user_name; IdMsg.Subject := theSubject; // Add the attachments. if Length(aryAttachmentFilenames) &gt; 0 then begin with TIdText.Create(IdMsg.MessageParts, nil) do begin Body.Text := 'An HTML viewer is required to see this message'; ContentType := 'text/plain'; end; with TIdText.Create(IdMsg.MessageParts, nil) do begin Body.Text := theBody; ContentType := 'text/html'; end; // Add each attachment. for i := Low(aryAttachmentFilenames) to High(aryAttachmentFilenames) do TIdAttachment.Create(IdMsg.MessageParts, aryAttachmentFilenames[i]); IdMsg.ContentType := 'multipart/mixed'; end else begin IdMsg.Body.Text := theBody; IdMsg.ContentType := 'text/html'; end; // if Length(aryAttachmentFilenames) &gt; 0 then theIdSmtp.Host := host; theIdSmtp.Username := user_name; theIdSmtp.Password := password; theIdSmtp.Port := port_number; // Use EHLO method. theIdSmtp.UseEhlo := true; // Login method of authentication. theIdSmtp.AuthenticationType := atLogin; // Connect to the desired SMTP server. N second time-out. theIdSmtp.Connect(connectTimeOut_ms); try // Send it. theIdSmtp.Send(IdMsg); // If we got here than the test succeeded. Set the flag // indicating the current settings are valid. Result := true; finally theIdSmtp.Disconnect; end; end; // with emailServerSettings do finally IdMsg.Free; end; // try end; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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