MT是否支持SMTP SendMail,或者我是否坚持使用MFMailComposeViewController?现在,我让它正常工作(MFMailComposeViewController),但是当我添加附件时,收件人没有收到邮件。
我想知道SMTP是否会更可靠并处理附件。
发布于 2011-01-17 04:48:47
是的,它是在System.Net.Mail下支持的,但不推荐使用,因为除非你在你的应用程序上请求,否则没有办法从系统中获得用户凭据,但我不知道这是否违反了苹果的EULA。
我已经用下面的代码成功地从iphone上发送了带有附件的电子邮件,希望这能有所帮助:)
MFMailComposeViewController _mail;
mailButton.TouchUpInside += (o, e) =>
{
byte[] data = File.ReadAllBytes("photo.png");
NSData datas = NSData.FromArray(data);
if (MFMailComposeViewController.CanSendMail)
{
_mail = new MFMailComposeViewController ();
_mail.SetMessageBody ("This is the body of the email", false);
_mail.AddAttachmentData(datas, "image/png", "photo.png");
_mail.Finished += delegate(object sender, MFComposeResultEventArgs e1)
{
if (e1.Result == MFMailComposeResult.Sent)
{
UIAlertView alert = new UIAlertView ("Mail Alert", "Mail Sent", null, "Success", null);
alert.Show ();
//you should handle other values that could be returned in e.Result and also in e.Error
}
e1.Controller.DismissModalViewControllerAnimated (true);
};
this.PresentModalViewController (_mail, true);
} else {
//handle not being able to send mail
}
};这里还有测试解决方案的链接,它基于mike bluestein的示例http://dl.dropbox.com/u/2058130/MailDemo.zip,它适用于我:)
希望这能有所帮助
亚历克斯
发布于 2011-01-16 22:27:49
不管它是否支持,你都不应该使用它。
您无法获取用户的SMTP连接设置,因此无法以用户身份发送邮件。
您不能假定用户的连接可以连接到您的服务器。
https://stackoverflow.com/questions/4705851
复制相似问题