我在asp中使用“createuserwizard”创建一个表单。这是我的代码。
<asp:CreateUserWizard ID="userwizard" ContinueDestinationPageUrl="~/secretfiles/secret.aspx" runat="server" >
<MailDefinition BodyFileName="register.txt" Subject="Registration Confirmation" From="amrit.enest@gmail.com" />
</asp:CreateUserWizard>
这是我的web.config文件设置。
<mailSettings>
<smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
<network host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com" password="sending emails's password" />
</smtp>
</mailSettings>
然后我选择了以下选项中的Smtp .in ISS设置。
->Use localhost(SMTP)
->port=25
->authentication not required
现在,当新用户单击“提交”按钮时,它会显示以下错误消息,并且不会发送邮件。
SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.7.0必须首先发出STARTTLS命令。 ud8sm21095949igb.4
请帮帮我们。
答案 0 :(得分:4)
使用enableSsl="true"
,如下所示:
<mailSettings>
<smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
<network enableSsl="true" host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com" password="sending emails's password" />
</smtp>
</mailSettings>
答案 1 :(得分:0)
服务器需要SSL,因此您需要将其添加到您的配置中:
<mailSettings>
<smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
<network host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com"
password="sending emails's password" enableSsl="true" />
</smtp>
</mailSettings>
有关详细信息,请参阅here。
答案 2 :(得分:0)
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
MailAddress from = new MailAddress("your mail address@mail.com");
SmtpClient clientobj = new SmtpClient("smtp.gmail.com");
mail.From = from;
mail.To.Add(new MailAddress(" to mail address@gmail.com"));
mail.Subject = "example gridview";
mail.Body+="Please check below data <br/><br/>";
mail.Body += getgridviewdata(gv1);
mail.IsBodyHtml = true;
clientobj.Credentials = new System.Net.NetworkCredential("your mailaddress@gmail.com", "your email password");
clientobj.Port =587;
clientobj.EnableSsl = true;
clientobj.Send(mail);
}
上面gv1中的是我的gridview id
public string getgridviewdata(GridView gv)
{
StringBuilder strBuilder = new StringBuilder();
StringWriter strWriter = new StringWriter(strBuilder);
HtmlTextWriter htw = new HtmlTextWriter(strWriter);
gv.RenderControl(htw);
return strBuilder.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
您也可以在源代码中编写以下内容
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="example.aspx.cs" Inherits="example" EnableEventValidation="false" %>