什么是错误。邮件不发送到注册邮件ID。 [英] What is error in this. Mail is not Sending to register mail id.
本文介绍了什么是错误。邮件不发送到注册邮件ID。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用系统;
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Web;
使用 System.Web.UI;
使用 System.Web.UI.WebControls;
使用 System.Data.SqlClient;
使用 System.Configuration;
使用 System.Text;
使用 System.Net;
使用 System.Net.Mail;
命名空间 logindemo
{
public partial class 注册:System.Web.UI.Page
{
protected void Page_Load( object sender,EventArgs e)
{
}
受保护 void btnRegister_Click( object sender,EventArgs e)
{
string connetionString = 数据源= INFND-DTP-0493;初始目录= Test_DB;用户ID = #####;密码= ## ###跨度>;
SqlConnection conn = new
SqlConnection(connetionString);
conn.Open();
string commText = select * from login user_name =' + txtUserName.Text.Trim()+ '或email_id =' + txtEmailId.Text.Trim()+ '或phone_no = + Convert.ToDouble (txtPhoneNo.Text);
SqlCommand cmd = new
SqlCommand(commText,conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Label1.Text = 重复数据;
}
else
{
conn.Close();
MailMessage消息;
string commText1 = 插入登录( User_Name,密码,地址,城市,州,PIN,Phone_no,Email_id,Created_By,Created_on)值(' + txtUserName.Text + ',' + txtPassword.Text + ',' + txtAddress.Text + ',' + txtCity.Text + ',' + txtState.Text + ',' + Convert.ToDouble(txtPin.Text)+ ',' + Convert.ToDouble(txtPhoneNo.Text)+ ',' + txtEmailId.Text + ',' + Alok + ',' + DateTime.Now + ')跨度>;
SqlCommand cmd1 = new
SqlCommand(commText1,conn);
conn.Open();
int no = cmd1.ExecuteNonQuery();
conn.Close();
if (no> 0)
{
Label1.Text = 用户注册成功;
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(txtEmailId.Text.Trim());
mail.From = new MailAddress( alokparhi06@gmail.com跨度>);
mail.Subject = 关于:注册确认;
mail.Body = 嗨 + txtUserName.Text.Trim()+ ,您已成功注册...;
mail.IsBodyHtml = true ;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential( alokparhi06@gmail.com, xyz);
client.Port = 587 ;
client.Host = smtp.gmail.com;
client.EnableSsl = true ;
尝试
{
client.Send(mail);
}
catch
{
Label1.Text = 发送消息时出现问题......;
}
}
其他
{
Label1.Text = 错误;
}
}
}
}
}
解决方案
之前我已经解决了这个相关的问题..检查这个参考..
参考:5.5.1需要身份验证
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Net;
using System.Net.Mail;
namespace logindemo
{
public partial class Register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnRegister_Click(object sender, EventArgs e)
{
string connetionString = "Data Source=INFND-DTP-0493;Initial Catalog=Test_DB;User ID=#####;Password=#####";
SqlConnection conn = new
SqlConnection(connetionString);
conn.Open();
string commText = "select * from login where user_name='"+txtUserName.Text.Trim()+"' or email_id= '" + txtEmailId.Text.Trim() +"' or phone_no=" + Convert.ToDouble(txtPhoneNo.Text) ;
SqlCommand cmd = new
SqlCommand(commText, conn);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Label1.Text = "Duplicte of Data";
}
else
{
conn.Close();
MailMessage msg;
string commText1 = "insert into login(User_Name,Password,Address,City,State,PIN,Phone_no,Email_id,Created_By,Created_on) values('" + txtUserName.Text + "','" + txtPassword.Text + "','" + txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + Convert.ToDouble(txtPin.Text) + "','" + Convert.ToDouble(txtPhoneNo.Text) + "','" + txtEmailId.Text + "','" + "Alok" + "','" + DateTime.Now + "')";
SqlCommand cmd1 = new
SqlCommand(commText1, conn);
conn.Open();
int no = cmd1.ExecuteNonQuery();
conn.Close();
if(no>0)
{
Label1.Text= "User registration sucessfully";
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add(txtEmailId.Text.Trim());
mail.From = new MailAddress("alokparhi06@gmail.com");
mail.Subject = "Regarding: Registration conformation";
mail.Body = "Hi"+txtUserName.Text.Trim()+", You have registered successfully...";
mail.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("alokparhi06@gmail.com", "xyz");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(mail);
}
catch
{
Label1.Text="There is some problem while sending Message... ";
}
}
else
{
Label1.Text="Error";
}
}
}
}
}
解决方案
Hi,
Previously i was solved this related question..check this ref..
Ref : 5.5.1 Authentication Required
这篇关于什么是错误。邮件不发送到注册邮件ID。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文