简体   繁体   English

挑战以asp.net形式邮寄

[英]challenging with mailing in asp.net form

i have made the this form and this C# code for mailing (Contact us form) ihave this error 我已经完成了此表单和此C#代码的邮寄(请与我们联系),我遇到了此错误

The SMTP server requires a secure connection or the client was not authenticated. SMTP服务器需要安全连接,或者客户端未通过身份验证。 The server response was: 5.7.0 Must issue a STARTTLS command first. 服务器响应为:5.7.0必须首先发出STARTTLS命令。 m2sm37748843wjf.42 - gsmtp m2sm37748843wjf.42-gsmtp

and this is my code 这是我的代码

protected void Page_Load(object sender, EventArgs e)
{
    lblError.Visible = false;
}

protected void Button1_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        try
        {
            string strbody = string.Empty;
            strbody += string.Format("<b>Name </b> :{0} <br /> ", TextboxName.Text);
            strbody += string.Format("<b>E-Mail</b>: <a href='mailto:{0}'>{0}</a><br />", textboxemail.Text);
            strbody += string.Format("<b> Subject</b> :{0} <br />", textboxwebsite.Text);
            strbody += string.Format("<b>Description</b>: {0}<br />",                           textboxmessage.Text.Replace("\n", "<br />"));

            System.Net.Mail.MailMessage oMailMessage = new                           System.Net.Mail.MailMessage();
            System.Net.Mail.MailAddress oMailAddress = null;
            oMailAddress = new System.Net.Mail.MailAddress
                (
                    "salarzardouz@gmail.com",
                    "Sent By salar zardouz website",
                    System.Text.Encoding.UTF8
                );
            oMailMessage.From = oMailAddress;
            oMailMessage.Sender = oMailAddress;
            oMailMessage.To.Clear();
            oMailMessage.CC.Clear();
            oMailMessage.Bcc.Clear();
            oMailMessage.ReplyToList.Clear();
            oMailMessage.Attachments.Clear();
            oMailMessage.ReplyToList.Add(oMailAddress);
            oMailMessage.Bcc.Add("salarzardouz@outlook.com");
            oMailAddress = new System.Net.Mail.MailAddress
                (
                    textboxemail.Text,
                    textboxmessage.Text,
                    System.Text.Encoding.UTF8
                );
            oMailMessage.To.Add(oMailAddress);

            oMailMessage.BodyEncoding = System.Text.Encoding.UTF8;
            oMailMessage.Body = strbody;

            oMailMessage.SubjectEncoding = System.Text.Encoding.UTF8;
            oMailMessage.Subject = "[-<Company Name>-] - " + textboxwebsite.Text;

            oMailMessage.IsBodyHtml = true;

            oMailMessage.Priority = System.Net.Mail.MailPriority.Normal;

            oMailMessage.DeliveryNotificationOptions =
                System.Net.Mail.DeliveryNotificationOptions.OnSuccess ;
            string strRootRelativePathName = "~/Attachments/Attachment.png";
            string strPathName = Server.MapPath(strRootRelativePathName);

            if (System.IO.File.Exists(strPathName))
            {
                System.Net.Mail.Attachment oAttachment =
                    new System.Net.Mail.Attachment(strPathName);

                oMailMessage.Attachments.Add(oAttachment);
            }
            System.Net.Mail.SmtpClient oSmtpClient =
                new System.Net.Mail.SmtpClient();
            oSmtpClient.Timeout = 100000;
            oSmtpClient.EnableSsl = false;
            oSmtpClient.Send(oMailMessage);

            string strInformationMessage =
                "Your Email Has been successfully sent";
            lblError.Visible = true;
            lblError.Text = strInformationMessage;
        }
        catch (System.Exception ex)
        {
            DisplayErrorMessage(ex.Message);
        }
    }
}
protected virtual void DisplayErrorMessage(string message)
{
    lblError.Visible = true;

    lblError.Text =
        string.Format("<div class='error'>{0}</div>", message);
}

Have you checked your email's server properties?? 您是否检查过电子邮件的服务器属性? Maybe you need a SSL authentication. 也许您需要SSL身份验证。

For example, on gmail you must authenticate: 例如,在gmail上,您必须进行身份验证:

smtp1.Host = "smtp.gmail.com"
        smtp1.Credentials = New System.Net.NetworkCredential("xxxx@xxxxx.com", "xxxxxxx")
        smtp1.Port = 587
        smtp1.EnableSsl = True
        smtp1.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network

        smtp1.Send(correo1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM