电子邮件发送失败错误geting请帮助我 [英] email sending fail error geting kindly help me

查看:74
本文介绍了电子邮件发送失败错误geting请帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Net;
using System.Net.Mail;

public partial class _Default : System.Web.UI.Page
{
	protected void Page_Load ( object sender, EventArgs e )
	{
	}

	protected void Button1_Click ( object sender, EventArgs e )
	{
	}

	protected void Button1_Click1 ( object sender, EventArgs e )
	{
		int userid = 0;
		string coone = ConfigurationManager.ConnectionStrings[ "hhConnectionString2" ].ConnectionString;
		SqlConnection con = new SqlConnection( coone );
		SqlCommand cmd = new SqlCommand( ( "admin11" ) );
		SqlDataAdapter adp = new SqlDataAdapter( );
		cmd.CommandType = CommandType.StoredProcedure;
		cmd.Parameters.AddWithValue( "@username", TextBox1.Text.Trim( ) );
		cmd.Parameters.AddWithValue( "@password", TextBox2.Text.Trim( ) );
		cmd.Parameters.AddWithValue( "@email", TextBox3.Text.Trim( ) );
		cmd.Connection = con;
		con.Open( );
		userid = Convert.ToInt32( cmd.ExecuteScalar( ) );
		con.Close( );
		string message = string.Empty;
		switch ( userid )
		{
			case -1:
			message = " username already exist";
			break;

			case -2:
			message = " supply mail address already in use";
			break;

			default:
			message = " registration succesful and userid " + userid.ToString( );
			activationclient( userid );
			break;
		}

		ClientScript.RegisterStartupScript( GetType( ), "alert", "alert('" + message + "');", true );
	}

	private void activationclient ( int userid )
	{
		string honey = ConfigurationManager.ConnectionStrings[ "hhConnectionString3" ].ConnectionString;
		string activationcode = Guid.NewGuid( ).ToString( );
		SqlConnection con = new SqlConnection( honey );
		SqlCommand cmd = new SqlCommand( "insert into active values(@userid, @activationcode)" );
		SqlDataAdapter adp = new SqlDataAdapter( );
		cmd.CommandType = CommandType.Text;
		cmd.Parameters.AddWithValue( "@userid", userid );
		cmd.Parameters.AddWithValue( "@activationcode", activationcode );
		cmd.Connection = con;
		con.Open( );
		cmd.ExecuteNonQuery( );
		con.Close( );
		MailMessage mm = new MailMessage( " sender@gmail.com", TextBox3.Text );
		mm.Subject = " account activation";
		string body = "hello" + TextBox1.Text.Trim( ) + ", ";
		body += " <br /><br /> please link on this for activation";
		body += " <br />&lt; a href = '" + Request.Url.AbsoluteUri.Replace( "cs.aspx", "cs_activation.aspx? + activationcode = " + activationcode ) + "' &gt; click here to activate your account .  ";
		mm.Body = body;
		mm.IsBodyHtml = true;
		SmtpClient smtp = new SmtpClient( );
		smtp.Host = "smtp.gmail.com";
		smtp.EnableSsl = true;
		NetworkCredential nn = new NetworkCredential( "sender@gmail.com", "<password>" );
		smtp.UseDefaultCredentials = true;
		smtp.Credentials = nn;
		smtp.Port = 587;
		smtp.Send( mm );
	}
}



邮件不发送请帮助我们


mail is not sending kindly help me guys

推荐答案





请尝试以下代码片段发送经过身份验证的电子邮件。



Hi,

Try below code snippet for sending an authenticated email.

public bool Send(string fromAddress, string fromText, string toAddress, string toText, string bccAddress, string bccText, string subject, StringBuilder plainBody, StringBuilder htmlBody)
{
    try
    {

        string strUname = "";// Username for Authentication
        string strpw = "";// Password for the Authentication
        string sSmtpHost = "";// SMTP Host


        oMail.From = new MailAddress(fromAddress, fromText);

        oMail.To.Add(new MailAddress(toAddress));

        oMail.Bcc.Add(new MailAddress(bccAddress));

        oMail.Subject = subject;
        oMail.Body = htmlBody.ToString();
        oMail.IsBodyHtml = true;

        SmtpClient oSmtp = new SmtpClient(sSmtpHost);
        oSmtp.Credentials = new System.Net.NetworkCredential(strUname, strpw);

        oSmtp.EnableSsl = false;// is Connection is Secure set true else false
        oSmtp.Send(oMail);


        return true;
    }
    catch (Exception Ex)
    {
        throw new Exception("Sending E-Mail failed." + Ex.Message.ToString(), Ex);
    }
}


你的代码OK。

你需要看到这个链接并关注步骤。



http://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-是 - 不是 [ ^ ]
your code OK.
You Need to just See This Link and Follow the Steps.

http://stackoverflow.com/questions/20906077/gmail-error-the-smtp-server-requires-a-secure-connection-or-the-client-was-not[^]


请检查以下几点。

1)安全连接 - 某些SMTP服务器需要安全连接,因此您应该检查 EnableSsl 是否为tue或false并检查一次。



2)强密码 - SMTP服务器使用不同类型的算法来检查密码是否强大,即使您提供了正确的密码它将被拒绝,所以请确保您的密码是强大的,不要忘记使用数字+ 1个符号+ 1个大写字母+ 6分钟字母= 10个字母,一旦您输入强密码,您的邮件永远不会被拒绝或认证问题。 />


3)域名提供商邮件 - 如果您从诸如godaddy或bigrock等域名提供商处购买了邮件帐户,那么您应该开发服务和托管服务它在同一台服务器上,通过使用WebRequest和WebResponse,您可以在应用程序中使用该服务。即使您提供了正确的凭据,域提供商服务器上的购买帐户也不允许您从您的应用程序发送邮件,因此您应该开发服务并且应该在他们的服务器上托管,然后只有您能够发送邮件。
Please check check the following points.
1)Secure Connection- Some SMTP server requires a secure connection so you should check EnableSsl either tue or false and check it once.

2)Strong Password- SMTP servers uses different types of algorithm to check the password is strong or not, even if you provide correct password it will be rejected so make sure your password is strong and don't forgot to use digits+1 symbol+1 caps letter+6 min letter=10 letters, once you make strong password your mail never goes rejected or authenticatio issues.

3)Domain Providers Mail- If you have purchased mail account from the domain providers like godaddy or bigrock that time you should develop a service and host it on same server, by using WebRequest and WebResponse you can use the service in your application. Purchased account from domain providers server will not allow you to send mail from your application even you provide correct credentials, so you should develop service and should host on their server then only you will be able to send the mails.


这篇关于电子邮件发送失败错误geting请帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆