是否有跨平台方式从FireMonkey启动电子邮件客户端,以便它可以在Windows和OS / X上运行。在Windows下我可以执行以下操作:
ShellExecute(0, 'OPEN', 'mailto:somebody@somewhere.com', '', '', SW_ShowDefault);
是否有跨平台等效于启动电子邮件客户端(最好带有附件,收件人,主题,正文等)?
答案 0 :(得分:6)
据我所知,没有跨平台的方式来发送邮件,但是使用Windows端的ShellExecute
函数和OSX的NSWorkspace.openURL,您可以编写自己的实现。
尝试此OSX实施。
uses
Macapi.Foundation,
Macapi.AppKit,
System.SysUtils;
Procedure SendMail(const Mailto,Subject, Body:string);
var
URL : NSURL;
AWorkspace : NSWorkspace;
encodedSubject,
encodedTo,
encodedBody : NSString;
begin
//NSString *encodedSubject = [NSString stringWithFormat:@"SUBJECT=%@", [subject stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
encodedSubject :=NSSTR(Format('SUBJECT=',[Subject])).stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
//NSString *encodedBody = [NSString stringWithFormat:@"BODY=%@", [body stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
encodedBody :=NSSTR(Format('BODY=',[Body])).stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
//NSString *encodedTo = [to stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
encodedTo :=NSSTR(Mailto).stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding);
//NSString *encodedURLString = [NSString stringWithFormat:@"mailto:%@?%@&%@", encodedTo, encodedSubject, encodedBody];
//NSURL *mailtoURL = [NSURL URLWithString:encodedURLString];
// [[NSWorkspace sharedWorkspace] openURL:mailtoURL];
URL := TNSURL.Create;
URL.initWithString(NSSTR(Format('mailto:%s?%s&%s',[ encodedTo.UTF8String, encodedSubject.UTF8String, encodedBody.UTF8String])));
AWorkspace := TNSWorkspace.Create;
AWorkspace.openURL(URL);
end;