[英]iOS Firemonkey: How to send email from iOS App though mail app in Firemonkey Delphi XE7
I am working with iOS App in Firemonkey using Delphi XE7. 我正在使用Delphi XE7在Firemonkey中使用iOS App。
Question: I need to send email from my iOS App through the mail app in Firemonkey. 问题:我需要通过Firemonkey中的邮件应用程序从iOS应用程序发送电子邮件。
I have seen other old blogs for sending an email but those solutions didn't help me. 我见过其他老博客发送电子邮件,但是这些解决方案对我没有帮助。
Below are the old links which I have tried it, but I couldn't solve. 以下是我尝试过的旧链接,但无法解决。
http://blogs.embarcadero.com/ao/2011/10/04/39133 http://blogs.embarcadero.com/ao/2011/10/04/39133
http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/ http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/
Kindly let me know some other solutions or samples. 请让我知道其他解决方案或示例。
Thanks in advance. 提前致谢。
Use the code from the second link you included: http://blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/ 使用您包含的第二个链接中的代码: http : //blogs.embarcadero.com/matthiaseissing/2013/05/03/38707/
It is for XE4 and you just need a few changes to make it work for XE7: 它适用于XE4,您只需要进行一些更改即可使其适用于XE7:
The StrToNSUrl
function has moved to the Macapi.Helpers
unit in XE7, so you must add that to your uses clause. StrToNSUrl
函数已移至Macapi.Helpers
中的Macapi.Helpers
单元,因此必须将其添加到uses子句中。 In addition the NSStr function is deprecated and so you should use StrToNSStr
instead (also from Macapi.Helpers). 另外,不建议使用NSStr函数,因此您应该改用
StrToNSStr
(同样来自Macapi.Helpers)。
Here is a function that puts all the functionality together: 这是一个将所有功能放在一起的功能:
procedure SendEmail(aEmail: string; aSubject: string = ''; aBody: string = '');
var lSharedApplication: UIApplication;
lURL: string;
begin
lURL := 'mailto:'+aEmail;
if (aSubject<>'') or (aBody<>'') then
begin
lURL := lURL+'?subject='+aSubject;
if aBody<>'' then
lURL := lURL+'&body='+aSubject;
lURL := StringReplace(lURL,' ','%20',[rfReplaceAll]); //replace spaces
lURL := StringReplace(lURL,sLineBreak,'%0D%0A',[rfReplaceAll]);//replace linebreaks
end;
lSharedApplication := TUIApplication.Wrap(TUIApplication.OCClass.SharedApplication);
lSharedApplication.openURL(StrToNSUrl(lURL));
end;
Call it like this: 这样称呼它:
SendEmail('name@email.nowhere','My subject','My body');
Use the TDPFMailCompose class that is included in DPF Delphi iOS Native Components 使用DPF Delphi iOS本机组件中包含的TDPFMailCompose类
That gives you more options than a mailto: link and you don't have to worry about the encoding. 这给您提供了比mailto:链接更多的选择,而您不必担心编码。 Internally this uses the iOS MFMailComposeViewController class.
内部使用iOS MFMailComposeViewController类。
Example: 例:
var
Mail: TDPFMailCompose;
begin
Mail := TDPFMailCompose.Create(nil);
if not Mail.MailCompose(Msg.Subject, Msg.Body, False, [Msg.To_], [Msg.CC], [Msg.BCC], [AttachedFileName]) then
MessageDlg('Error sending mail', TMsgDlgType.mtError, [TMsgDlgBtn.mbClose], -1);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.