Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:23:50+00:00 2026-06-05T07:23:50+00:00

I have a Delphi 6 application that generates E-mails that I send to my

  • 0

I have a Delphi 6 application that generates E-mails that I send to my Evernote E-mail address, a special E-mail address for sending documents via E-mail so that they are stored automatically into my Evernote account.

I have successfully created HTML documents and sent them to my Evernote E-mail address using the Indy 9.x TIdSMTP component. I set the Content-Type to ‘text/html‘. It works fine as long as I don’t add any attachments to the E-mail. As soon as I add an attachment, something about the generated E-mail makes the Evernote web interface interpret the E-mail as raw HTML. In other words, I see the raw HTML in the document display area as if I had done “view-source” in a browser, instead of seeing a rendered web page. The E-mail attachments I am adding are an AVI file and a WAV file if that matters. When I do add attachments both of them show up properly at the bottom of the E-mail in the Evernote web display area.

To repeat, as soon as I don’t add attachments the document shows up as a pretty web page in the Evernote web interface. If I add attachments, I see raw HTML. Can anyone suggest something I can try to fix this problem? I have enclosed the code I use to send the generated document to my Evernote E-mail address below. The variable named body contains a fully formatted HTML document.

UPDATE: I sent the E-mail to a non-Evernote E-mail address so I could see the raw E-mail message. I turns out that adding attachments makes TIdSMTP change the Content-Type of the first part of the multi-part E-mail it generates back to ‘text/plain’ despite the fact I set it to ‘text/html’ in my code when I create the message. I’m going to have a look at the Indy source and see if I can figure out what is going wrong.

function easySendEmail(
                theIdSmtp               : TIdSmtp;
                destEMailAddress        : string;
                subject                 : string;
                body                    : string;
                emailServerSettings     : TEmailServerSettingsRecord;
                aryAttachmentFilenames  : TDynamicStringArray;
                connectTimeOut_ms       : integer;
                bUseEHLO                : boolean;
                authLoginType           : TAuthenticationType): boolean;
var
    IdMsg: TIdMessage;
    aryAttachments: TDynamicIdAttachmentArray;
    i: integer;
begin
    aryAttachments := nil;
    IdMsg := nil;

    destEMailAddress := Trim(destEMailAddress);

    if destEMailAddress = '' then
       raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The destination E-mail address is empty.');

    subject := Trim(subject);

    if subject = '' then
        raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The subject line is empty.');

    body := Trim(body);

    if body = '' then
        raise Exception.Create('(TframeEmailServerSettings.easySendEmail) The message body is empty.');

    try
        with emailServerSettings do
        begin
            // Build a test message and send it.
            IdMsg := TIdMessage.Create(nil);
            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 := subject;
            IdMsg.Body.Text := body;

            IdMsg.ContentType :=  'text/html';
            // IdMsg.ContentType :=  'text/plain';

            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;

            // Add the attachments.

            // >>> If I comment out the code below the document shows
            //  up as a rendered web page in the Evernote web interface.
            //  If I uncomment it and therefore add attachments, the
            //  document shows up as raw HTML.
            {
            if Length(aryAttachmentFilenames) > 0 then
            begin
                SetLength(aryAttachments, Length(aryAttachmentFilenames));

                for i := Low(aryAttachmentFilenames) to High(aryAttachmentFilenames) do
                    // Add each attachment.
                    aryAttachments[i] := TIdAttachment.Create(IdMsg.MessageParts, aryAttachmentFilenames[i]);
            end; // if Length(aryAttachmentFilenames) > 0 then
            }

            // Connect to the desired SMTP server.  N second time-out.
            theIdSmtp.Connect(connectTimeOut_ms);

            // Send it.
            theIdSmtp.Send(IdMsg);

            // If we got here than the test succeeded.  Set the flag
            //  indicating the current settings are valid.
            Result := true;
        end; // with mergeEditsWithOriginal do

    finally
        theIdSmtp.Disconnect;

        if Assigned(IdMsg) then
            IdMsg.Free;
    end; // try
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:23:51+00:00Added an answer on June 5, 2026 at 7:23 am

    Your code is not setting up TIdMessage correctly when attachments are present. Try this instead:

    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) > 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) > 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; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Delphi application that has a document browser as the main form.
I have a Delphi 6 application that asks the user to select an audio
I have a Delphi 2009 application that runs a query over a database using
I have a process that currently runs in a Delphi application that I wrote
I have an application that called several other .exe components written in delphi. The
I have written a console application in Delphi that queries information from several locations.
I have an ISAPI Application in Delphi 6 that uses WebBroker. I need to
I have an application written in Delphi that adds / updates contacts in outlook.
We have a Windows desktop application written in Delphi that works fine on Windows
I have a Delphi 6 application that is heavily multithreaded. I have a component

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.