【发布时间】:2021-11-11 13:58:15
【问题描述】:
当点击发送按钮时,会调用以下代码:
protected void btnSend_Click(object sender, System.EventArgs e)
{
// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient();
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress(txtEmail.ToString().Trim(),
txtName.ToString() + (char)0xD8,
System.Text.Encoding.UTF8);
// Set destinations for the email message.
MailAddress to = new MailAddress("nyamathulani@gmail.com");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = txtMsg.ToString();
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = txtSubject.ToString() + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// The userToken is a string constant.
string userState = "Thulani awaits your message";
client.SendAsync(message, userState);
btnSend.Text = "Sending...";
// Clean up.
message.Dispose();
}
]2我希望能够从 ASP.NET 网络表单发送电子邮件,而无需在代码中使用我的密码,因为我正在构建投资组合网站并需要使用我的个人电子邮件地址
【问题讨论】:
-
您的应用程序是如何托管的?预置?天蓝色? AWS?去吧爸爸?其他一些主机?
-
目前在本地服务器上,打算托管在 Github 页面或 Azure 上
-
使用 Azure,最好的办法是使用服务器端电子邮件发送并将您的凭据保存在 KeyVault 中。我还建议使用专用于此应用程序的电子邮件帐户。
-
@Fildor,如果这能解决我的问题,感谢您更新
-
顺便说一句,如果它只是一个“联系”表单,您绝对可以将其制作为带有表单的静态网页,并将数据发送到各种“HTML 表单到电子邮件”提供商之一,如果这就是它的全部。
标签: c# asp.net email webforms passwords