[英]Send email from Xamarin.Forms app using Dependency Service
In my app, for debugging purposes and testing purposes I need to send an email. 在我的应用程序中,出于调试目的和测试目的,我需要发送电子邮件。
How do I present the mail controller, when the class that sends it does not contain a definition for PresentViewController
? 当发送邮件的类未包含
PresentViewController
的定义时,如何显示邮件控制器? The class needs to fire off the email app after the user clicks "yes" from the alert which fires. 用户在触发的警报中单击“是”后,该类需要触发电子邮件应用程序。
public async Task<bool> SendEmail(Exception ex)
{
var result = await SendNotificationToRequestSendingEmail();
if (result)
{
if (MFMailComposeViewController.CanSendMail)
{
mailController = new MFMailComposeViewController();
mailController.SetToRecipients(new string[] { "test@one.com", "test@two.com" });
mailController.SetSubject("Details");
mailController.SetMessageBody($"Message: {ex.Message}" +
$"Exception: {ex.ToString()}"
, false);
mailController.Finished += (object s, MFComposeResultEventArgs args) =>
{
Console.WriteLine(args.Result.ToString());
args.Controller.DismissViewController(true, null);
};
this.PresentViewController(mailController, true, null); //this line causes the error
}
}
return true;
}
How can I fix this problem or get around it? 我该如何解决或解决这个问题? This is called from a Xamarin Forms page.
这是从Xamarin表单页面调用的。
Please take a look at this answer: 请看一下这个答案:
Sending e-mail from Gmail in Xamarin.Forms app 在Xamarin.Forms应用中从Gmail发送电子邮件
besides that you can also do it with this NuGet package: 除此之外,您还可以使用此NuGet包来做到这一点:
https://www.nuget.org/packages/Xam.Plugins.Messaging/ https://www.nuget.org/packages/Xam.Plugins.Messaging/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.