xamarin - 在 Xamarin Forms 中使用邮件服务时,我们如何获取 SmtpServer NetworkCredentials?
问题描述
我正在Forgot password
我的 Xamarin Forms 应用程序中实现一个简单的功能。当玩家email
在文本字段中提供一个时,将检查该电子邮件是否存在于数据库中,如果存在,将获取与该电子邮件关联的密码并将密码发送到该电子邮件。
在下面的 smtp 步骤SmtpServer.Credentials = new System.Net.NetworkCredential("email", "password");
中,我们从哪里获取凭据以Network credentials
作为电子邮件/密码提供?
namespace soccerapp
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ForgotPassword : ContentPage
{
private SQLiteConnection conn;
string emailText;
public ForgotPassword()
{
InitializeComponent();
conn = DependencyService.Get<Isqlite>().GetConnection();
}
public void btnSend_Clicked(object sender, EventArgs e)
{
emailText = txtEmail.Text;
int count = (from x in conn.Table<PlayerDetails>().Where(x => x.Email == emailText) select x).Count();
if (count != 0)
{
var detail = conn.Table<PlayerDetails>().First(x => x.Email == emailText);
var playerPassword = detail.Password;
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("admin@somesite.nz");
mail.To.Add(emailText);
mail.Subject = "Hello";
mail.Body = "Your soccer password: "+playerPassword;
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential("some_email@gmail.com", "password");
SmtpServer.Send(mail);
}
catch (Exception ex)
{
DisplayAlert("Faild", ex.Message, "OK");
}
}
}
}
}
解决方案
推荐阅读
- sql - 当查询限制来自另一个没有连接的表时,我可以从一个表中选择一个值吗?
- amazon-web-services - 如何在 AWS EC2 上公开和访问 API 服务端点
- python - 如何在 Seaborn JointPlot 上设置标题?
- c++ - 如何在 C++ 中使用 Autolt 解密功能?
- javascript - expressjs REST API 的好模式?
- python - 如何运行包内的 shell 脚本?
- reactjs - AWS Amplify / Dynamo - 作为字符串数组返回的对象数组
- c++ - 使用 C++20 概念实现 Pair 概念
- python - 使用循环反转字符串的函数
- python-3.x - How can I save a PNG image greater than 90 KB?