You can send E-Mails using the RTC SDK via the Mailgun API, but you have a few errors in your code.
Since I don't know what else you've changed, the easiest way to fix your example Project is to ...
1. Load the original
ClientFormPost example from the
QuickStart folder.
2. Replace "Button1Click" and "RtcDataRequest1BeginRequest" implementations with the code below, to reflect the CURL example you've posted above (EXACTLY) ...
procedure TForm1.Button1Click(Sender: TObject);
begin
RtcHttpClient1.ServerAddr := '
api.mailgun.net';
RtcHttpClient1.ServerPort := '
443';
RtcHttpClient1.UseSSL :=
True;
RtcDataRequest1.Request.Method:='
POST'; // Use the "HTTP POST" method
RtcDataRequest1.Request.FileName:='
/v3/YOUR_DOMAIN_NAME/messages';
RtcDataRequest1.Request.Host:=
RtcHttpClient1.ServerAddr; // Set the "Host" HTTP header
RtcDataRequest1.Post(); // Post the request to the request queue
end;
procedure TForm1.RtcDataRequest1BeginRequest(Sender: TRtcConnection);
var
Cli:TRtcDataClient absolute Sender;
begin
Cli.Request.ContentType:='
application/x-www-form-urlencoded'; // important!!!
// Set the "Authorization" parameter using mime/base64 encoding
Cli.Request['
Authorization'] :=
'Basic '+Mime_Encode('
api:YOUR_API_KEY');
// Set all POST variables
Cli.Request.Params['
from']:=URL_Encode('
Excited User <YOU@YOUR_DOMAIN_NAME>');
Cli.Request.Params['
to']:=URL_Encode('
Foo <foo@example.com>');
Cli.Request.Params['
cc']:=URL_Encode('
Bar <bar@example.com>');
Cli.Request.Params['
bcc']:=URL_Encode('
Baz <baz@example.com>');
Cli.Request.Params['
subject']:=URL_Encode('
Hello');
Cli.Request.Params['
text']:=URL_Encode('
Testing some Mailgun awesomness!');
// When sending body as text (line above), sending body as HTML (line below) is optional (not required) ...
Cli.Request.Params['
html']:=URL_Encode('
<html>HTML version of the body</html>');
// Use the "Write" method to send "Params.Text" ("FORM-URLENCODED" values) to the Server
Cli.Write(
Cli.Request.Params.Text);
end;
3. Modify
RED_BOLD_TEXT and (blue) E-Mail Addresses above to reflect YOUR parameters. If you skip this step (3), but everything else is correct, you should get a response from the Server "401 UNAUTHORIZED / Forbidden".
Best Regards,
Danijel Tkalcec