[英]How to create a secure “Contact me” form in ASP.NET?
Please help, 请帮忙,
I need to add a "Contact me" form to my website, most of tutorials almost use the same approach, but all of them don't work properly; 我需要在我的网站上添加一个“联系我”表格,大多数教程几乎都使用相同的方法,但是它们都无法正常工作。 instead of receiving the visitor message I receive a security problem warning like this:
我没有收到访客消息,而是收到这样的安全问题警告:
Here is the code I used (outlook and gmail interact in the same way): 这是我使用的代码(outlook和gmail以相同的方式交互):
//this the event handler of the send button //这是发送按钮的事件处理程序
protected void ButtonSend_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
string fileName = Server.MapPath("~/App_Data/Message.txt");
string mailBody = File.ReadAllText(fileName);
mailBody = mailBody.Replace("##Name##", TextBoxName.Text);
mailBody = mailBody.Replace("##Email##", TextBoxEmail.Text);
mailBody = mailBody.Replace("##Subject##", TextBoxSubject.Text);
mailBody = mailBody.Replace("##Body##", TextBoxBody.Text);
MailMessage visitorMessage = new MailMessage();
visitorMessage.Subject = "New Message: " + TextBoxSubject.Text;
visitorMessage.Body = mailBody;
visitorMessage.From = new MailAddress(TextBoxEmail.Text, TextBoxName.Text);
visitorMessage.To.Add(new MailAddress("asdfg@outlook.com", "Mohamed"));
visitorMessage.ReplyToList.Add(new MailAddress(TextBoxEmail.Text));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(visitorMessage);
LabelIRespond.Visible = true;
}
}
and for web.config: 对于web.config:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Mohamed <asdfg@outlook.com>">
<network host="Smtp.live.com" port="587" enableSsl="true" userName="asdfg@outlook.com" password="myOutlookPassword" />
</smtp>
</mailSettings>
</system.net>
Please help me figure out what am I missing here, no one talk about this issue when they create such forms, I hope I find the solution here? 请帮我弄清楚我在这里缺少什么,当他们创建这样的表格时没有人谈论这个问题,希望我在这里找到解决方案?
Thanks. 谢谢。
Most email services will fight you hard on allowing an application to log in and use it programmatically like this (in fact I think many have Terms of Use which prohibit this). 大多数电子邮件服务会在允许应用程序这样登录并以编程方式使用它的过程中奋力拼搏 (事实上,我认为许多人都有使用条款禁止这样做)。 This is how spammers would use a service to spam people if they could.
垃圾邮件发送者将以此方式使用服务向垃圾邮件发送者发送垃圾邮件。 Instead you need to find a service that will allow you to send emails via an API, or set up your own SMTP server.
相反,您需要找到一种服务,该服务将允许您通过API发送电子邮件,或设置自己的SMTP服务器。
I would suggest something like SendGrid: https://sendgrid.com/pricing , they have a free plan that includes 12,000 emails per month. 我会建议类似SendGrid的网站: https ://sendgrid.com/pricing,他们有一个免费计划,每月包括12,000封电子邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.