0
我无法使用MailKit
库jstedfast从xamarin.android应用程序发送电子邮件。无法使用Mailkit从xamarin.android应用程序发送电子邮件
我使用下面的代码:
try
{
//From Address
string FromAddress = "[email protected]";
string FromAdressTitle = "Email Title";
//To Address
string ToAddress = "[email protected]";
string ToAdressTitle = "Address Title";
string Subject = "Subject of mail";
string BodyContent = "Body of email";
//Smtp Server
string SmtpServer = "smtp.gmail.com";
//Smtp Port Number
int SmtpPortNumber = 587;
var mimeMessage = new MimeMessage();
mimeMessage.From.Add(new MailboxAddress(FromAdressTitle, FromAddress));
mimeMessage.To.Add(new MailboxAddress(ToAdressTitle, ToAddress));
mimeMessage.Subject = Subject;
mimeMessage.Body = new TextPart("plain")
{
Text = BodyContent
};
using (var client = new SmtpClient())
{
client.Connect(SmtpServer, SmtpPortNumber, false);
// Note: only needed if the SMTP server requires authentication
// Error 5.5.1 Authentication
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate("[email protected]", "password");
client.Send(mimeMessage);
Console.WriteLine("The mail has been sent successfully !!");
Console.ReadLine();
client.Disconnect(true);
}
}
catch (Exception ex)
{
string message = ex.Message;
}
当我运行从我的应用程序的代码,它抛出一个异常:
MailKit.Security.AuthenticationException
我在想什么这段代码。任何人都可以帮助我!
我尝试这样做,则抛出异常:“{System.Net.Mail.SmtpException:534-5.7.14
您需要允许安全性较低的应用访问您的Gmail帐户。 https://support.google.com/accounts/answer/6010255?hl=zh-CN –
谢谢,它允许访问后帮助。 –