c# - 使用 ASP.Net 发送电子邮件而不在代码中显示我的密码
问题描述
当点击发送按钮时,会调用以下代码:
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 Web 表单发送电子邮件,而无需在代码中使用我的密码,因为我正在构建投资组合网站并且需要使用我的个人电子邮件地址
解决方案
我认为无论如何您都必须在代码中输入密码,或者您必须手动设计,以便在发送电子邮件时输入密码。
推荐阅读
- bash - shell脚本逐行从文本文件中读取文件名并确认它们存在于两个不同的目录中
- genymotion - Genymotion 不显示任何内容,并且在启动时出现白屏
- python - 不平衡数据集中的多类分类
- objective-c - 何时可以安全地重写和重用 MTLBuffer 或其他 Metal 顶点缓冲区?
- amazon-web-services - Vpc 链接尚不可用于部署
- java - JsonB、JPA、REST、CDI、生成不完整的 JSON
- mysql - 如果表为空,Laravel 中间件重定向
- python - 超过Mysql插入锁等待超时 - 自动增量
- python - 安装 Sherlock 时的问题
- c# - 我真的需要一个静态类来管理收藏夹吗?