Sending an email from an iOS FireMonkey application

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.

One Response to “Sending an email from an iOS FireMonkey application” Says:

[...] 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.

Close
del.icio.us Digg Furl Netscape Yahoo! My Web StumbleUpon Google Bookmarks Technorati BlinkList Newsvine ma.gnolia reddit Windows Live Tailrank
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值