我如何通过Asp .Net跟踪电子邮件发送或不通过? [英] How I can track Email send or Not Through Asp .Net?

查看:49
本文介绍了我如何通过Asp .Net跟踪电子邮件发送或不通过?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我已经写了一封用于在asp .net上发送电子邮件的代码,但我想跟踪另一端发送的电子邮件记录电子邮件。

这是我的EmailSend代码: -

  public   void  Sendmail( string  ECandidateName)
{
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress( 电子邮件地址 名称);
smtpClient.Host = smtp.gmail.com;
smtpClient.Port = 587 ;
message.From = fromAddress;
message.To.Add(txtEmail.Text);
message.Subject = 感谢您的连接我们;
message.Bcc.Add( emailid);
message.Bcc.Add( new MailAddress( EMAILID));
message.IsBodyHtml = false ;
message.Body = 请求的数量
smtpClient.Credentials = < span class =code-keyword> new
System.Net.NetworkCredential( EmailId 密码);
smtpClient.EnableSsl = true ;
smtpClient.Send(message);

// lblStatus.Text =电子邮件已成功发送。;
}
catch (例外情况)
{
Response.Write( < script> alert(' + ex.Message + ')< /脚本>中);
// lblStatus.Text =发送电子邮件失败。< br> + ex.Message;
}
}



}



此代码工作正常,但有时它不会将电子邮件发送到我在To选项中提到的特定地址。我想跟踪电子邮件,如果电子邮件是否发送到接收方端

谢谢,

问候

Naveen

解决方案

好的。只做一件事。



按照我的回答 - 从asp.net发送电子邮件到gmail [ ^ ],复制代码并替换所有gmail凭据和要发送邮件的地址。 />


这是一个正常工作的代码。



让我知道它是否适合你。

嗨....

一旦检查一下,可能有用u。



 MailMessage myMail =  new  MailMessage(); 
SmtpClient smtpclient = new SmtpClient();
// mail fromaddress
MailAddress fromadrress = new MailAddress( mailid);
myMail.From = fromadrress;
// 邮件主题
myMail.Subject = + YourSubject.Text + ;

// string url =+ HttpContext.Current.Request.Url.AbsoluteUri + ;
// 链接
// string link = url.Replace(yyy,xxxx);
myMail.IsBodyHtml = true ;
// 邮件正文内容
myMail.Body = + Comments.Text + < br />< br />< br />< br />< br />< br />感谢和问候,< br /> ; + YourName.Text + ;
// mail toaddress
MailAddress Toadd = MailAddress(YourEmail.Text);
myMail.To.Add( + Toadd + );

smtpclient.Host = hostname;
smtpclient.Port = portno;
smtpclient.Credentials = new System.Net.NetworkCredential( mailid password);
smtpclient.Send(myMail);



谢谢。


您可以使用 SmtpFailedRecipientsException 来跟踪哪个成员未能收到电子邮件。



  public   static   void  RetryIfBusy( string  server)
{
MailAddress 来自 = MailAddress( ben@contoso.com);
MailAddress to = new MailAddress( jane @ contoso.com);
MailMessage message = new MailMessage( from ,to);
// message.Subject =使用SmtpClient类。;
message.Subject = 使用SmtpClient类。;
message.Body = @ 使用此功能,您可以从应用程序发送电子邮件消息容易
// 添加抄送收件人。
MailAddress copy = new MailAddress( Notifications@contoso.com) ;
message.CC.Add(copy);
SmtpClient client = new SmtpClient(服务器);
// 如果服务器需要,请包含凭据。
client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
Console.WriteLine( 使用SMTP主机{1}向{0}发送电子邮件。
to.Address,client.Host);
尝试
{
client.Send(message);
}
catch (SmtpFailedRecipientsException ex)
{
for int i = 0 ; i < ex.InnerExceptions.Length; i ++)
{
SmtpStatusCode status = ex.InnerExceptions [i] .StatusCode;
if (status == SmtpStatusCode.MailboxBusy ||
status == SmtpStatusCode.MailboxUnavailable)
{
Console。 WriteLine( 传递失败 - 在5秒后重试。);
System.Threading.Thread.Sleep( 5000 );
client.Send(message);
}
else
{
Console.WriteLine( 无法将消息传递给{0}
ex.InnerExceptions [i] .FailedRecipient);
}
}
}
catch (例外情况)
{
Console.WriteLine ( 在RetryIfBusy()中捕获异常:{0}
ex.ToString( ));
}
}





更多细节请查看 SmtpFailedRecipientsException类 [ ^ ]


Hi all,
I''ve Written a code for email send in asp .net but i want to track the email record email send on the other end or not.
Here is my EmailSend code:-

public void Sendmail(string ECandidateName)
    {
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();
        try
        {
            MailAddress fromAddress = new MailAddress("Email Address", "Name");
            smtpClient.Host = "smtp.gmail.com";
            smtpClient.Port = 587;
           message.From = fromAddress;
            message.To.Add(txtEmail.Text);
            message.Subject = "Thank you for your Connecting Us";
           message.Bcc.Add("emailid");
          message.Bcc.Add(new MailAddress("Emailid"));
            message.IsBodyHtml = false;
            message.Body = "Thnks for Request"
            smtpClient.Credentials = new System.Net.NetworkCredential("EmailId", "Password");
            smtpClient.EnableSsl = true;
              smtpClient.Send(message);

           // lblStatus.Text = "Email successfully sent.";
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('"+ex.Message+"')</script>");
           // lblStatus.Text = "Send Email Failed.<br>" + ex.Message;
        }
    }
   


} 


this code is working fine but some times it doesn''t send the email to particular address which I''ve mention in To option.I want to track the email if the email is send or not towards the receivers end
Thanks,
Regards
Naveen

解决方案

Ok. Just do one thing.

Follow my answer - sending email to gmail from asp.net[^], copy the code and replace all your gmail credentials and the address you want to send the mail to.

This is a working code.

Let me know if it works for you or not.


Hi....
once check this,may useful u.

MailMessage myMail = new MailMessage();
SmtpClient smtpclient = new SmtpClient();
// mail fromaddress
MailAddress fromadrress = new MailAddress("mailid");
myMail.From = fromadrress;
//mail subject
myMail.Subject = ""+YourSubject.Text+"";

//string url = "" + HttpContext.Current.Request.Url.AbsoluteUri + "";
//for link
//string link = url.Replace("yyy", "xxxx");
myMail.IsBodyHtml = true;
//mail body content
myMail.Body = "" + Comments.Text + "<br /><br /><br /><br /><br /><br />  Thanks&Regards,<br />" + YourName.Text + "";
//mail toaddress
MailAddress Toadd= new MailAddress(YourEmail.Text);                       
myMail.To.Add("" + Toadd + "");

smtpclient.Host = "hostname";
smtpclient.Port = portno;
smtpclient.Credentials = new System.Net.NetworkCredential("mailid", "password");
smtpclient.Send(myMail);   


thank u.


You can use SmtpFailedRecipientsException to track which member are failed to receive emails.

public static void RetryIfBusy(string server)
{
	MailAddress from = new MailAddress("ben@contoso.com");
	MailAddress to = new MailAddress("jane@contoso.com");
	MailMessage message = new MailMessage(from, to);
	// message.Subject = "Using the SmtpClient class.";
	message.Subject = "Using the SmtpClient class.";
	message.Body = @"Using this feature, you can send an e-mail message from an application very easily.";
	// Add a carbon copy recipient.
	MailAddress copy = new MailAddress("Notifications@contoso.com");
	message.CC.Add(copy);
	SmtpClient client = new SmtpClient(server);
	// Include credentials if the server requires them.
	client.Credentials = (ICredentialsByHost)CredentialCache.DefaultNetworkCredentials;
	Console.WriteLine("Sending an e-mail message to {0} using the SMTP host {1}.",
		 to.Address, client.Host);
	try
	{
		client.Send(message);
	}
	catch (SmtpFailedRecipientsException ex)
	{
		for (int i = 0; i < ex.InnerExceptions.Length; i++)
		{
			SmtpStatusCode status = ex.InnerExceptions[i].StatusCode;
			if (status == SmtpStatusCode.MailboxBusy ||
				status == SmtpStatusCode.MailboxUnavailable)
			{
				Console.WriteLine("Delivery failed - retrying in 5 seconds.");
				System.Threading.Thread.Sleep(5000);
				client.Send(message);
			}
			else
			{
				Console.WriteLine("Failed to deliver message to {0}", 
				    ex.InnerExceptions[i].FailedRecipient);
			}
		}
	}
    catch (Exception ex)
    {
        Console.WriteLine("Exception caught in RetryIfBusy(): {0}", 
                ex.ToString() );
    }
}



for more details check SmtpFailedRecipientsException Class[^]


这篇关于我如何通过Asp .Net跟踪电子邮件发送或不通过?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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