无法使用Godaddy专业电子邮件帐户从asp.net发送电子邮件

时间:2020-10-08 12:34:28

标签: c# asp.net email shared-hosting

我有一个asp.net Web应用程序,该应用程序有一个查询页面,我想将查询从该页面发送到我的gmail帐户,我正在使用godaddy专业电子邮件帐户从该网页发送邮件。 但是它不会出于我未知的原因发送电子邮件。

这是我的前端代码:

    <form id="contactform" name="contact_form" runat="server">
    <input type="text" id="form_name" value="" runat="server" placeholder="Your Name*" required=""/>
    <input type="email" id="form_email" value="" runat="server" placeholder="Your Mail*" required=""/>
    <input type="text" id="form_phone" value="" runat="server" placeholder="Phone"/>
    <textarea id="form_message" runat="server" placeholder="Your Message.." required=""></textarea>
    <input id="form_botcheck" name="form_botcheck" type="hidden" value=""/>
    <asp:Button CssClass="thm-btn bg-cl-1" runat="server" id="send" Text="Send" OnClick="send_Click" />                        
    </form>'

这是我后面的代码。 我正在使用...

System.Net;
System.Net.Mail;

// .......

    $public static void SendEmail(string emailbody)
    {
    //email code snippet
    
    // Specify the from and to email address
    MailMessage mailMessage = new MailMessage("mymail@mydomain.com", "mymail@gmail.com");
    // Specify the email body
    mailMessage.Body = emailbody;
    // Specify the email Subject
    mailMessage.Subject = "Enquiry";
    
    // Specify the SMTP server name and port number
    SmtpClient smtpClient = new SmtpClient("relay-hosting.secureserver.net", 25);
    // Specify your mail address and password
    smtpClient.Credentials = new System.Net.NetworkCredential()
    {
    UserName = "mymail@mydomain.com",
    Password = "mypassword"
    };
    // Gmail works on SSL, so set this property to true
    smtpClient.EnableSsl = false;
    // Finall send the email message using Send() method
    smtpClient.Send(mailMessage);
    }
    
    protected void send_Click(object sender, EventArgs e)
    {
    Page.Validate();
    if (Page.IsValid)
    {
    try
    {
    String str1 = form_name.Value;
    String str2 = form_email.Value;
    String str3 = form_phone.Value;
    String str4 = form_message.Value;
    
    String emailbody = "Name : " + str1 + "\r\n" + "e-mail : " + str2 + "\r\n" + "Contact Number : " + str3 + "\r\n" + "Message : " + str4 + "\r\n";
    
    SendEmail(emailbody);
    
    form_name.Value = "";
    form_email.Value = "";
    form_phone.Value = "";
    form_message.Value = "";
    
    ClientScript.RegisterStartupScript(GetType(), "hwa", "alert('Your Enquiry has been submitted');", true);
    Response.Redirect(Request.Url.AbsoluteUri);
    }
    catch (Exception em) { Response.Write(em.Message); }
    }
    else
    {
    ClientScript.RegisterStartupScript(GetType(), "hwa", "alert('Please enter the required information and submit');", true);
    }            
    }

当我从事另一个项目时,此代码工作了1-2年。

0 个答案:

没有答案