本文介绍了电子邮件发送失败错误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( " [email protected]", 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( "[email protected]", "<password>" );
		smtp.UseDefaultCredentials = true;
		smtp.Credentials = nn;
		smtp.Port = 587;
		smtp.Send( mm );
	}
}



邮件不发送请帮助我们


mail is not sending kindly help me guys

推荐答案

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);
    }
}




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

09-02 00:46