使用预定义的电子邮件地址从 iPhone 发送电子邮件

发布于 2024-09-09 08:51:42 字数 641 浏览 1 评论 0原文

我想让用户可以发送来自预定义电子邮件地址的电子邮件地址。因此用户没有指定电子邮件地址。

但是,我希望他们能够定义收件人的电子邮件和电子邮件地址的内容。

这是我之前尝试使用的,它通过邮件客户端:

NSString *emailInfo = [NSString stringWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]];

问题是,我想让它如此 MAIL & SUBJECT 类似于 UITextFields 中使用的 toEmailcontent 变量。

我尝试使用 stringWithFormat 但它不起作用。

有什么想法吗?

谢谢

I'd like to make it so the user can send an email address which comes from a predefined email address. So the user does not specify the email address.

However, I'd like it so they do define the recipient's email and the content of the email address.

This is what I tried using earlier, which goes through the Mail client:

NSString *emailInfo = [NSString stringWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]];

The thing is, I want to make it so MAIL & SUBJECT resemble the toEmail and content variables which are used in UITextFields.

I tried using stringWithFormat but it didn't work.

Any ideas?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2024-09-16 08:51:42

尝试

-(IBAction)sendEmail:(id)sender { 
NSURL* mailURL = [NSURL URLWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!"]; [[UIApplication sharedApplication] openURL: mailURL]; 
} 

Try

-(IBAction)sendEmail:(id)sender { 
NSURL* mailURL = [NSURL URLWithString: @"mailto:[email protected][email protected]&subject=Greetings%20from%Cupertino!&body=Wish%20you%20were%20here!"]; [[UIApplication sharedApplication] openURL: mailURL]; 
} 
醉酒的小男人 2024-09-16 08:51:42
NSString *emailInfo = [NSString initWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]]

错误的可能原因是 NSURL 对象:
我猜 [NSURL URLWithString: emailInfo] 返回 null。

尝试打印到控制台

 NSLog(@"URL = %@", [NSURL URLWithString: emailInfo]);

所以我建议您进行字符串编码。

NSString *emailInfo = [NSString stringWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [emailInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
NSString *emailInfo = [NSString initWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: emailInfo]]

Probable cause of error is NSURL object:
I guess [NSURL URLWithString: emailInfo] is returning null.

Try printing to console

 NSLog(@"URL = %@", [NSURL URLWithString: emailInfo]);

So I would suggest you to go for string encoding.

NSString *emailInfo = [NSString stringWithString: @"mailto:[email protected]&subject=SUBJECT"];
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString: [emailInfo stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文