Home how to get bounce mail reports and status code with reason without using third party tool in C#
Reply: 0

how to get bounce mail reports and status code with reason without using third party tool in C#

user3485
1#
user3485 Published in April 26, 2018, 5:37 am

how to get bounce mail reports and status code with reason without using third party tool in C# After sending mails in bulk mails is sending successfully but cant retrieve status code of mail from smtp server, please give suggestion??

public ActionResult Index(Champain champain, HttpPostedFileBase fileUploader)
        {
            var domain = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + (Request.Url.IsDefaultPort ? "" : ":" + Request.Url.Port);

            if (ModelState.IsValid)
            {
                try
                {
                    var contat = db.Contacts.Where(x => x.ContactListId == champain.ContactListId).ToList();
                    var smtpdetail = db.SmtpDetails.Where(x => x.Id == champain.SmtpId).FirstOrDefault();
                    foreach (var item in contat)
                    {

                            champain.ContactId = item.Id;
                            champain.SendOn = DateTime.UtcNow;
                            champain.IsOpen = false;
                            champain.Name = champain.Name.Trim();
                            var champains = db.Champains.Add(champain);
                            db.SaveChanges();
                            string url = domain + "/Champain/IsOpen?ChampionId=" + champains.Id;
                            string imageTag = "<img src='" + url + "' width='1' height='1' />";

                            MailMessage mail = new MailMessage(smtpdetail.Name, item.Email);
                            mail.Subject = champain.Subject;
                            mail.IsBodyHtml = true;
                            champain.Body += imageTag;
                            mail.Body = champain.Body;
                            if (fileUploader != null)
                            {
                                string fileName = Path.GetFileName(fileUploader.FileName);
                                mail.Attachments.Add(new Attachment(fileUploader.InputStream, fileName));
                            }
                            SmtpClient client = new SmtpClient();
                            client.DeliveryMethod = SmtpDeliveryMethod.Network;
                            client.UseDefaultCredentials = false;
                            client.EnableSsl = true;
                            client.Host = smtpdetail.HostName;
                            client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                            client.Credentials = new System.Net.NetworkCredential(smtpdetail.Username, smtpdetail.Password);
                            client.Port = Convert.ToInt32(smtpdetail.Port);


                            mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure |
                   DeliveryNotificationOptions.OnSuccess;

                        try
                        {
                            client.Send(mail);
                        }
                        catch (SmtpException ex)
                        {
                            Console.WriteLine("Error: {0}", ex.StatusCode);
                        }

                        db.SaveChanges();
                    }
                }
                catch (Exception Ex)
                {
                }
                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.359117 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO