如何制作一个“联系我们”表单,允许用户从任何域(gmail,hotmail,yahoo等)向管理员发送电子邮件。我的意思是,任何在其电子邮件中拥有任何域名的用户都可以向管理员的电子邮件地址发送电子邮件。目前,只有拥有Gmail帐户的用户才能发送电子邮件。请帮助并提供任何解决方案和建议。 感谢。
答案 0 :(得分:0)
在Asp.net中,您可以设置任何域的用户电子邮件,但它应该有效。在From Property of Mail类中设置用户电子邮件。
protected void SendMail()
{
// Gmail Address from where you send the mail
var fromAddress = "Gmail@gmail.com";
// any address where the email will be sending
var toAddress = YourEmail.Text.ToString();
//Password of your gmail address
const string fromPassword = "Password";
// Passing the values and make a email formate to display
string subject = YourSubject.Text.ToString();
string body = "From: " + YourName.Text + "\n";
body += "Email: " + YourEmail.Text + "\n";
body += "Subject: " + YourSubject.Text + "\n";
body += "Question: \n" + Comments.Text + "\n";
// smtp settings
var smtp = new System.Net.Mail.SmtpClient();
{
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.Timeout = 20000;
}
// Passing values to smtp object
smtp.Send(fromAddress, toAddress, subject, body);
}
来自地址的可以是任何有效的电子邮件地址。