Q: How do you send an email from the iPhone using FireMonkey?
A: By opening a mailto URL
Below is a very simple unit that will do the trick. Just create a brand new iOS FireMonkey application, and add two edit boxes and one memo. The first edit box will hold the email address we’re sending the email to. The second edit box will contain the subject line, and the memo will contain the actual email body.
Notice that this opens the local email client and you have to send it manually. It does *not* send the email in the background.
Enjoy!
unit Unit1;
{$IFDEF FPC}
{$mode objfpc}{$H+}
{$modeswitch objectivec1}
{$ENDIF}
interface
uses
SysUtils, Types, UITypes, Classes, Variants, FMX_Types, FMX_Controls, FMX_Forms,
FMX_Dialogs, FMX_Layouts, FMX_Memo, FMX_Edit
{$IFDEF FPC}
, iPhoneAll
{$ENDIF}
;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ToStr, SubjectStr, BodyStr : String;
URL : NSString;
begin
{$IFDEF FPC}
ToStr := Edit1.Text;
SubjectStr := Edit2.Text;
BodyStr := Memo1.Text;
URL := NSSTR(PChar(’mailto:’+ToStr+’?subject=’+SubjectStr+’&body=’+BodyStr));
URL := URL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
UIApplication.sharedApplication.openUrl(NSURL.URLWithString(URL));
{$ENDIF}
end;
end.
This entry was posted on Tuesday, October 4th, 2011 at 11:42 am and is filed under Delphi, Delphi XE2, FireMonkey, RAD Studio XE2, ednfront, iOS, iPhone. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
[...] Sending an email from an iOS FireMonkey application [...]
Leave a Reply The Hacker’s Corner is proudly powered by WordPress MU running on Embarcadero Blogs. Create a new blog and join in the fun!
Entries (RSS) and Comments (RSS).
Bad Behavior has blocked 512 access attempts in the last 7 days.