Posts Tagged 'SMTP Mail'

NetworkCredential in SMTP mail (Forms Authentication)

In the project I am currently working on we have to send email confirmation to the registered user giving them their User ID and Password (yup… saw that right password….not secured but that is the requirement :-(). we created a no-reply account and to our amazement all emails sent inside our domain were reaching fine but external domains were not. My hardware tech lead (Mihai) helped me out in checking exchange server(since I didnt have access to it). We saw that no mails to external domain was even queued in exchange. Then Mihai came up to me and asked me to check the credentials which was used for sending email and that was the missing piece :-). Prior to this application all our apps were windows authenticated so there was no need to specify the Network Credentials but in this app we have to use forms authentication since it is an internet site not an intranet site. So added the following line and it worked like charm 🙂

System.Net.NetworkCredential objAuthInfo = new NetworkCredential("<username>", "<password>");

objSMTP.Credentials = objAuthInfo;

Hope this helps.

Happy Programming!!!