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

  • Home
  • SEARCH
  • 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 9198309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:15:21+00:00 2026-06-17T22:15:21+00:00

I am using the Indy TIdHTTP component and am successfully able to send emails

  • 0

I am using the Indy TIdHTTP component and am successfully able to send emails via the sendgrid API using the following function. The sendgrid api documentation can be found here.

Now I am tasked with including file attachments. In the API documentation it states: The file contents must be part of the multipart HTTP POST

I have attempted to modify my function to include the TIdMultipartFormDataStream with no success.

How should I modify the code to support file attachments?

procedure SendGridEmailProc;
var
  IdHTTP1: TIdHTTP;
  IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocketOpenSSL;
  mString: string;
  mParams: TStringList;
  i: Integer;
begin
  try
    mParams := TStringList.Create;
    IdHTTP1 := TIdHTTP.create(nil);
    IdSSLIOHandlerSocket1 := TIdSSLIOHandlerSocketOpenSSL.create(nil);
    with IdSSLIOHandlerSocket1 do begin
      SSLOptions.Method := sslvSSLv3;
      SSLOptions.Mode :=  sslmUnassigned;
      SSLOptions.VerifyMode := [];
      SSLOptions.VerifyDepth := 2;
    end;
    with IdHTTP1 do begin
      IOHandler := IdSSLIOHandlerSocket1;
    end;


    mParams.Add('api_user=xxxxx');
    mParams.Add('api_key=xxxxx');
    mParams.Add('to=xxxxxx');
    mParams.Add('from=xxxxx');

    mParams.Add('subject=test:'+datetimetostr(now));

    mParams.Add('text=this is a test');

    IdHTTP1.Post('https://sendgrid.com/api/mail.send.xml',mParams);


  finally
    mParams.Free;
    idhttp1.free;
    IdSSLIOHandlerSocket1.Free;
  end;
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-17T22:15:22+00:00Added an answer on June 17, 2026 at 10:15 pm

    Try to do it this way (note, that it’s untested):

    uses
      IdException, IdHTTP, IdSSLOpenSSL, IdMultipartFormData;
    
    procedure SendGridEmailProc;
    var
      HTTPClient: TIdHTTP;
      Parameters: TIdMultiPartFormDataStream;
      SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
    begin
      HTTPClient := TIdHTTP.Create(nil);
      try
        SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
        try
          SSLHandler.SSLOptions.Method := sslvSSLv3;
          SSLHandler.SSLOptions.Mode := sslmUnassigned;
          SSLHandler.SSLOptions.VerifyMode := [];
          SSLHandler.SSLOptions.VerifyDepth := 2;
          HTTPClient.IOHandler := SSLHandler;
    
          Parameters := TIdMultiPartFormDataStream.Create;
          try
            Parameters.AddFormField('api_user', 'xxxxx');
            Parameters.AddFormField('api_key', 'xxxxx');
            Parameters.AddFormField('to', 'xxxxxx');
            Parameters.AddFormField('from', 'xxxxx');
            Parameters.AddFormField('subject', 'test:' + DateTimeToStr(Now));
            Parameters.AddFormField('text', 'this is a test');
    
            // note, that you need to use the same file name for the files[]
            // identifier and that you should explicitly specify the content 
            // type for a file field to meet the HTTP dump shown in the help
            Parameters.AddFile('files[file.jpg]', 'c:\file.jpg', 
              'application/octet-stream');
    
            try
              HTTPClient.Post('https://sendgrid.com/api/mail.send.xml', 
                Parameters);
            except
              on E: EIdException do
                ShowMessage(E.ClassName + ': ' + E.Message);
            end;
          finally
            Parameters.Free;
          end;
        finally
          SSLHandler.Free;
        end;
      finally
        HTTPClient.free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My apps send emails using the Indy TiDSMTP client component. In some situations however,
I am trying to send emails from smtps (secure smtp) using Indy and the
I have built a simple website monitoring application using Indy TIdhttp component. I want
I am using the Indy TIdSmtp component to send E-mails. The E-mails I am
I want to send some binary data over via GET using the Indy components.
I'm using the TIdSSLIOHandlerSocketOpenSSL Indy component in Delphi XE2 to send data to an
I'm trying to send a file using POST in multipart/form data via Indy 10.5.8.
I'm using the IdFTP (Indy 10) component to download some files (zip and txt)
I am trying to send an e-mail using gmail account (Delphi 7, Indy 10)
I have been using Indy to transfers files via FTP for years now but

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.