Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
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:-
C#
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
Posted
Updated 7-May-13 20:35pm
v2
Comments
Thanks7872 8-May-13 2:38am    
want to track the email record email send on the other end or not? is only possible if you have access to the address to which you are sending mail.!some times it doesn't send the email to particular address,what does it mean?is it showing any error or what?
If the address is wrong, then how can it send ? Please explain the problem.
Naveen Kumar Kaushik 8-May-13 8:29am    
it doesn't show any error or exception.my code not able to send the email on particular emailid which i want to send.
Please follow my answer Solution 3.

Thanks,
Tadit

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.
 
Share this answer
 
Comments
VICK 26-Oct-13 7:20am    
Hi Tadit.. I have tried your code in the above given link and found the following exception.
Can you explain me a bit please.


System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at EmailTry.btnEmail_Click(Object sender, EventArgs e)
VICK 26-Oct-13 7:22am    
Sorted out.. mistake was mine.. Credentials issue. :) Thanks.
Good to hear that. Most welcome. Please accept this answer. We need to close this thread. :)
Hi....
once check this,may useful u.

C#
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.
 
Share this answer
 
v3
You can use SmtpFailedRecipientsException to track which member are failed to receive emails.

C#
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[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900