0

如何制作“联系我们”表单,允许用户从任何域(gmail、hotmail、yahoo 等)向管理员发送电子邮件。我的意思是任何在其电子邮件中具有任何域的用户都可以向管理员的电子邮件地址发送电子邮件。目前,只有拥有 Gmail 帐户的用户才能发送电子邮件。请帮助并提供任何解决方案和建议。谢谢。

4

1 回答 1

0

在 Asp.net 中,您可以设置任何域的​​用户电子邮件,但它应该是有效的。在 Mail 类的 From 属性中设置用户电子邮件。

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);
}

fromAddress 可以是任何有效的电子邮件地址。

于 2013-02-26T06:33:51.213 回答