Title: Send email via Mailgun API Post by: giancarlo on January 04, 2017, 05:36:07 AM Hi Danijel
I need to send an email via the Mailgun API. I modify the rtcClientFormPost sample to complete my test: The Mailgun Api give the following example: Code: curl -s --user 'api:YOUR_API_KEY' \ Then I did the following in the rtcClientFormPost sample: Code: procedure TForm1.Button1Click(Sender: TObject); Then when i click the Post button nothing happened, the program say that "No Responding" , for 30 seconds and then it come back, but there is not message, no error, no respond, and no email. What is wrong?, could i use RCT to send email in that way, using the Mailgun API. Thanks in advanced. Giancarlo Title: Re: Send email via Mailgun API Post by: D.Tkalcec (RTC) on January 04, 2017, 09:44:03 AM 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 Title: Re: Send email via Mailgun API Post by: giancarlo on January 04, 2017, 02:30:26 PM Hi Danijel,
Now it works!!! ;D Thank you very much!!! ;) Giancarlo Title: Re: Send email via Mailgun API Post by: D.Tkalcec (RTC) on January 04, 2017, 02:34:07 PM Good 8) Thanks for your feedback.
Best Regards, Danijel Tkalcec |