【问题标题】:Making a contact form that sends an email from any domain制作从任何域发送电子邮件的联系表
【发布时间】:2013-02-26 06:27:34
【问题描述】:

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

【问题讨论】:

    标签: asp.net forms email


    【解决方案1】:

    在 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 可以是任何有效的电子邮件地址。

    【讨论】:

    • 似乎我只能将它与 gmail ids 的“fromAddress”一起使用。如果用户可以从任何地址发送邮件可能是 gmail、yahoo、hotmail 等怎么办?
    • 用户可以从任何地址发送邮件,可以是gmail,yahoo,hotmail,带有“fromAddress”。
    • 当我使用 gmail 帐户作为“fromaddress”时它可以工作。但是当我尝试使用 yahoo 或 hotmail 的任何其他帐户时,它会给出错误“SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。"
    • 我正在使用这个 smtp.Host = "smtp.gmail.com";
    • 在 IIS 中配置 SMTP 服务器并在代码中使用该服务器。关于配置 SMTP 服务器,可以根据自己的 IIS 版本上网查询。
    猜你喜欢
    • 2020-05-20
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 2018-04-15
    • 2019-10-03
    • 2020-05-05
    • 1970-01-01
    • 2020-12-07
    相关资源
    最近更新 更多