Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1589
  • Last Modified:

How to send mail to an exchange email using smtp in asp.net?

Hi, i'm trying to send an email through smtp client in asp.net. It's ending with an error saying "Failure sending mail" and having inner exception as "Unable to read data from the transport connection: net_io_connectionclosed". I've tried surfing google to get this resolved and found few smtp.ServicePoint parameters to be setup but all that didn't work.

What i've come to know from my client is that the Mail Service is acquired from "networkdogsinc.com" and the mail address is an Exchange email. So far i've worked simple mail servers in asp.net and has developed working solutions but with Exchange Server it's my first experience. Also i didn't know how to access the "mail.combslawgroup.com" directly other than code or any mailing tool like outlook.

Please review the code attached for reference. Note that the From and To email address is same in this case (because this is for a Contact us page). Also the SMTPUid and SMTPPwd parameters in real code.

Please any one there to help me to get this resolved as it's a problem on one of my live sites.

Regards.
try
                {
                    MailMessage email = new MailMessage();
 
                    email.From = new MailAddress("mail@server.com");
                    email.To.Add("mail@server.com");
                    email.Subject = "Contact Us Email Subject";
                    email.Body = "email body";
 
                    SmtpClient smtp = new SmtpClient("mail.combslawgroup.com");
                    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                    smtp.ServicePoint.MaxIdleTime = 1000;
                    smtp.ServicePoint.ConnectionLimit = 1;
                    email.IsBodyHtml = true;
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = new System.Net.NetworkCredential("SMTPUid", "SMTPPwd");
                    smtp.Send(email);
 
                    return "Your request has been submitted successfully.";
                }
                catch (Exception ex)
                {
                    return "An error occured while sending email to admin. Error :: " + ex.Message;
                }

Open in new window

0
23-degrees
Asked:
23-degrees
  • 2
  • 2
  • 2
1 Solution
 
23-degreesAuthor Commented:
Thanks for the reply but the links provided targets asp classic based code where as i need any resource for ASP.Net. Can you spell any example with asp.net code that would be sending mail to an exchange mailbox?
0
 
florin_sCommented:
let me search a bit more, I'm not that good in writing code
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LeeDerbyshireCommented:
Have you configured Exchange to allow the computer that this code is running on (even if it's on the Exchange server itself) to relay messages through it?
0
 
23-degreesAuthor Commented:
I'm not new to exchange server. Can you please let me know how to set up the exchange so as it may allow relaying if it is hosted by a hosting company?
0
 
LeeDerbyshireCommented:
Which version of Exchange?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now