How do I generate multipart/form-data for email attachment sent via a bulk email APIUpload file with form data using Delphi Indy HTTP componentPython API calls multipart/form-dataHow can a Delphi Program send an Email with Attachments via the DEFAULT E-mail Client?Example of multipart/form-dataWhat does enctype='multipart/form-data' mean?How to send a “multipart/form-data” with requests in python?Post values in HTMLforms without using TwebBrowserTool for sending multipart/form-data requestC# HttpClient 4.5 multipart/form-data uploadhow to send email attachments using curl phpGMAIL API for sending Email with attachmentHow can i send a PDF as an attachment , if I only have the PDF URL
How do I deal with an unproductive colleague in a small company?
Why doesn't H₄O²⁺ exist?
What does "Puller Prush Person" mean?
What does the "remote control" for a QF-4 look like?
meaning of に in 本当に?
What's that red-plus icon near a text?
How does one intimidate enemies without having the capacity for violence?
What is a clear way to write a bar that has an extra beat?
How much RAM could one put in a typical 80386 setup?
Today is the Center
NMaximize is not converging to a solution
DC-DC converter from low voltage at high current, to high voltage at low current
Why do I get two different answers for this counting problem?
How does quantile regression compare to logistic regression with the variable split at the quantile?
LWC SFDX source push error TypeError: LWC1009: decl.moveTo is not a function
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
RSA: Danger of using p to create q
infared filters v nd
Replacing matching entries in one column of a file by another column from a different file
Was any UN Security Council vote triple-vetoed?
How to determine what difficulty is right for the game?
What are these boxed doors outside store fronts in New York?
Does an object always see its latest internal state irrespective of thread?
Is it possible to do 50 km distance without any previous training?
How do I generate multipart/form-data for email attachment sent via a bulk email API
Upload file with form data using Delphi Indy HTTP componentPython API calls multipart/form-dataHow can a Delphi Program send an Email with Attachments via the DEFAULT E-mail Client?Example of multipart/form-dataWhat does enctype='multipart/form-data' mean?How to send a “multipart/form-data” with requests in python?Post values in HTMLforms without using TwebBrowserTool for sending multipart/form-data requestC# HttpClient 4.5 multipart/form-data uploadhow to send email attachments using curl phpGMAIL API for sending Email with attachmentHow can i send a PDF as an attachment , if I only have the PDF URL
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm experimenting with sending emails through a bulk email sender via their API.
The code that works at the moment to send a simple email is this (INetHttp1
is of type TINetHttp
):
procedure TForm1.GenerateSendMailRequest;
var
fullURL, s : string;
Stream: TIdMultiPartFormDataStream;
begin
try
Stream.AddFile('attachfile','C:UsersAdminDocumentsage breakdown plot.pdf','<multipart/alternative>');
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
fullURL := 'https://api.elasticemail.com/v2/email/send'
+'?apikey=e123456-cacb-4456-112a-d145e7f55a47'
+'&subject=test 3 from elastic mail'
+'&from=myemail.co.uk'
+'&To=recipient1@hotmail.com;recipient2@gmail.com'
+'&bodyText=this is the body of the mail';
//?? how do I get the stream into the URL?
try
INetHttp1.Flags := [flSecure];
INetHttp1.Verb := veGet;
INetHttp1.Url := fullURL;
INetHttp1.Open;
INetHttp1.OpenRequest;
INetHttp1.SendRequest;
s := string(INetHttp1.ReadData);
finally
INetHttp1.Close;
Stream.free
end;
ShowMessage(s) //show server reponse
end;
To include an attachment (mine will be a PDF), their API documentation says:
Attach the file as POST multipart/form-data file upload
One of the examples says
You need to provide your attachments as the Multipart/Form-Data POST field in your Send request
But I am not at all clear on how to do this in Delphi 2009. I've seen StackOverflow answers that mention it, and in particular this post explains how to make a TIdMultiPartFormDataStream
.
Please, can somebody help me with the code to get that stream 'inserted' into the url that I send to the API?
A comment in another StackOverflow question said the OP should give a link to the API docs, so here it is, and here are some examples in languages which I'm not familiar with, although I can sort of understand the C# one.
I've looked at this question and this one, plus lots of others, but cannot see any relevant examples using Delphi 2009.
delphi multipartform-data email-attachments delphi-2009
add a comment |
I'm experimenting with sending emails through a bulk email sender via their API.
The code that works at the moment to send a simple email is this (INetHttp1
is of type TINetHttp
):
procedure TForm1.GenerateSendMailRequest;
var
fullURL, s : string;
Stream: TIdMultiPartFormDataStream;
begin
try
Stream.AddFile('attachfile','C:UsersAdminDocumentsage breakdown plot.pdf','<multipart/alternative>');
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
fullURL := 'https://api.elasticemail.com/v2/email/send'
+'?apikey=e123456-cacb-4456-112a-d145e7f55a47'
+'&subject=test 3 from elastic mail'
+'&from=myemail.co.uk'
+'&To=recipient1@hotmail.com;recipient2@gmail.com'
+'&bodyText=this is the body of the mail';
//?? how do I get the stream into the URL?
try
INetHttp1.Flags := [flSecure];
INetHttp1.Verb := veGet;
INetHttp1.Url := fullURL;
INetHttp1.Open;
INetHttp1.OpenRequest;
INetHttp1.SendRequest;
s := string(INetHttp1.ReadData);
finally
INetHttp1.Close;
Stream.free
end;
ShowMessage(s) //show server reponse
end;
To include an attachment (mine will be a PDF), their API documentation says:
Attach the file as POST multipart/form-data file upload
One of the examples says
You need to provide your attachments as the Multipart/Form-Data POST field in your Send request
But I am not at all clear on how to do this in Delphi 2009. I've seen StackOverflow answers that mention it, and in particular this post explains how to make a TIdMultiPartFormDataStream
.
Please, can somebody help me with the code to get that stream 'inserted' into the url that I send to the API?
A comment in another StackOverflow question said the OP should give a link to the API docs, so here it is, and here are some examples in languages which I'm not familiar with, although I can sort of understand the C# one.
I've looked at this question and this one, plus lots of others, but cannot see any relevant examples using Delphi 2009.
delphi multipartform-data email-attachments delphi-2009
2
The code you say "works" doesn't actually work, because you are not creating theTIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use itsTIdHTTP
component? It has aPost()
overload specifically forTIdMultipartFormDataStream
. In any case,multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/howTInetHttp
allows you to set the body data using aTStream
when sending a request.TInetHttp
is a 3rd party component, and I can't find documentation for it.
– Remy Lebeau
Mar 22 at 0:51
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
if you are going to build themultipart/form-data
manually, I suggest you read RFC 7578
– Remy Lebeau
Mar 22 at 16:27
add a comment |
I'm experimenting with sending emails through a bulk email sender via their API.
The code that works at the moment to send a simple email is this (INetHttp1
is of type TINetHttp
):
procedure TForm1.GenerateSendMailRequest;
var
fullURL, s : string;
Stream: TIdMultiPartFormDataStream;
begin
try
Stream.AddFile('attachfile','C:UsersAdminDocumentsage breakdown plot.pdf','<multipart/alternative>');
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
fullURL := 'https://api.elasticemail.com/v2/email/send'
+'?apikey=e123456-cacb-4456-112a-d145e7f55a47'
+'&subject=test 3 from elastic mail'
+'&from=myemail.co.uk'
+'&To=recipient1@hotmail.com;recipient2@gmail.com'
+'&bodyText=this is the body of the mail';
//?? how do I get the stream into the URL?
try
INetHttp1.Flags := [flSecure];
INetHttp1.Verb := veGet;
INetHttp1.Url := fullURL;
INetHttp1.Open;
INetHttp1.OpenRequest;
INetHttp1.SendRequest;
s := string(INetHttp1.ReadData);
finally
INetHttp1.Close;
Stream.free
end;
ShowMessage(s) //show server reponse
end;
To include an attachment (mine will be a PDF), their API documentation says:
Attach the file as POST multipart/form-data file upload
One of the examples says
You need to provide your attachments as the Multipart/Form-Data POST field in your Send request
But I am not at all clear on how to do this in Delphi 2009. I've seen StackOverflow answers that mention it, and in particular this post explains how to make a TIdMultiPartFormDataStream
.
Please, can somebody help me with the code to get that stream 'inserted' into the url that I send to the API?
A comment in another StackOverflow question said the OP should give a link to the API docs, so here it is, and here are some examples in languages which I'm not familiar with, although I can sort of understand the C# one.
I've looked at this question and this one, plus lots of others, but cannot see any relevant examples using Delphi 2009.
delphi multipartform-data email-attachments delphi-2009
I'm experimenting with sending emails through a bulk email sender via their API.
The code that works at the moment to send a simple email is this (INetHttp1
is of type TINetHttp
):
procedure TForm1.GenerateSendMailRequest;
var
fullURL, s : string;
Stream: TIdMultiPartFormDataStream;
begin
try
Stream.AddFile('attachfile','C:UsersAdminDocumentsage breakdown plot.pdf','<multipart/alternative>');
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
fullURL := 'https://api.elasticemail.com/v2/email/send'
+'?apikey=e123456-cacb-4456-112a-d145e7f55a47'
+'&subject=test 3 from elastic mail'
+'&from=myemail.co.uk'
+'&To=recipient1@hotmail.com;recipient2@gmail.com'
+'&bodyText=this is the body of the mail';
//?? how do I get the stream into the URL?
try
INetHttp1.Flags := [flSecure];
INetHttp1.Verb := veGet;
INetHttp1.Url := fullURL;
INetHttp1.Open;
INetHttp1.OpenRequest;
INetHttp1.SendRequest;
s := string(INetHttp1.ReadData);
finally
INetHttp1.Close;
Stream.free
end;
ShowMessage(s) //show server reponse
end;
To include an attachment (mine will be a PDF), their API documentation says:
Attach the file as POST multipart/form-data file upload
One of the examples says
You need to provide your attachments as the Multipart/Form-Data POST field in your Send request
But I am not at all clear on how to do this in Delphi 2009. I've seen StackOverflow answers that mention it, and in particular this post explains how to make a TIdMultiPartFormDataStream
.
Please, can somebody help me with the code to get that stream 'inserted' into the url that I send to the API?
A comment in another StackOverflow question said the OP should give a link to the API docs, so here it is, and here are some examples in languages which I'm not familiar with, although I can sort of understand the C# one.
I've looked at this question and this one, plus lots of others, but cannot see any relevant examples using Delphi 2009.
delphi multipartform-data email-attachments delphi-2009
delphi multipartform-data email-attachments delphi-2009
edited Mar 22 at 0:34
Remy Lebeau
342k19268461
342k19268461
asked Mar 21 at 22:52
user2834566user2834566
14519
14519
2
The code you say "works" doesn't actually work, because you are not creating theTIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use itsTIdHTTP
component? It has aPost()
overload specifically forTIdMultipartFormDataStream
. In any case,multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/howTInetHttp
allows you to set the body data using aTStream
when sending a request.TInetHttp
is a 3rd party component, and I can't find documentation for it.
– Remy Lebeau
Mar 22 at 0:51
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
if you are going to build themultipart/form-data
manually, I suggest you read RFC 7578
– Remy Lebeau
Mar 22 at 16:27
add a comment |
2
The code you say "works" doesn't actually work, because you are not creating theTIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use itsTIdHTTP
component? It has aPost()
overload specifically forTIdMultipartFormDataStream
. In any case,multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/howTInetHttp
allows you to set the body data using aTStream
when sending a request.TInetHttp
is a 3rd party component, and I can't find documentation for it.
– Remy Lebeau
Mar 22 at 0:51
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
if you are going to build themultipart/form-data
manually, I suggest you read RFC 7578
– Remy Lebeau
Mar 22 at 16:27
2
2
The code you say "works" doesn't actually work, because you are not creating the
TIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use its TIdHTTP
component? It has a Post()
overload specifically for TIdMultipartFormDataStream
. In any case, multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/how TInetHttp
allows you to set the body data using a TStream
when sending a request. TInetHttp
is a 3rd party component, and I can't find documentation for it.– Remy Lebeau
Mar 22 at 0:51
The code you say "works" doesn't actually work, because you are not creating the
TIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use its TIdHTTP
component? It has a Post()
overload specifically for TIdMultipartFormDataStream
. In any case, multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/how TInetHttp
allows you to set the body data using a TStream
when sending a request. TInetHttp
is a 3rd party component, and I can't find documentation for it.– Remy Lebeau
Mar 22 at 0:51
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
if you are going to build the
multipart/form-data
manually, I suggest you read RFC 7578– Remy Lebeau
Mar 22 at 16:27
if you are going to build the
multipart/form-data
manually, I suggest you read RFC 7578– Remy Lebeau
Mar 22 at 16:27
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290415%2fhow-do-i-generate-multipart-form-data-for-email-attachment-sent-via-a-bulk-email%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55290415%2fhow-do-i-generate-multipart-form-data-for-email-attachment-sent-via-a-bulk-email%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
The code you say "works" doesn't actually work, because you are not creating the
TIdMultipartFormDataStream
object before adding content to it. Also, if you are going to use Indy anyway, why not use itsTIdHTTP
component? It has aPost()
overload specifically forTIdMultipartFormDataStream
. In any case,multipart/form-data
cannot be sent in a URL, it must be send in an HTTP message body instead. So you need to check if/howTInetHttp
allows you to set the body data using aTStream
when sending a request.TInetHttp
is a 3rd party component, and I can't find documentation for it.– Remy Lebeau
Mar 22 at 0:51
@ Remy, as usual helpful and constructive comments. By 'works' I meant it sends an email (first ever one I've tried using an API call). I added TIdMultipartFormDataStream afterwards but got stuck re what to do with it, hence the post. I'd rather not use Indy if I can help it as I have had complications with it running on different PCs. Didn't realise TInetHttp was 3rd party, must've been installed a longtime ago! I shouldn't have asked a question that used it. So I need to build a complete message first and send that as the msg part of the API call. I'll search SO for how I build the msg.
– user2834566
Mar 22 at 7:49
if you are going to build the
multipart/form-data
manually, I suggest you read RFC 7578– Remy Lebeau
Mar 22 at 16:27