2012-02-28 59 views

回答

6

據我所知,沒有跨平臺的方式發送郵件,但使用windows的ShellExecute函數和NSWorkspace.openURL的OSX,你可以編寫你自己的實現。

試試這個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; 
+3

+1有人想知道Emba是否打算爲這類事物添加一個抽象層,或者它是否必須來自第三方開發人員。 – 2012-02-28 08:06:55

相關問題