简体   繁体   中英

Unable to send Email Using SmtpClient in asp.net

I am not able to send email in server if increasing timeout property.

//set the SMTP info
                SmtpClient smtp = new SmtpClient();
                smtp.Host = strServer;  //IP Mail Server
                smtp.Timeout = 70 * 60 * 1000;
                smtp.Port = Convert.ToInt16(Port); //Port
                smtp.Credentials = new System.Net.NetworkCredential(FromAddress, strPassword);       
                //send the email
                smtp.Send(Msg);

In my application i want to send 'B'-day mail nearly 1000 people. so i will send emails "To" those who hve birthday and put "bcc" to rest of the employees nearly 1000.if am not adding bcc it is working perfectly .if i'm adding bcc(1000 people) its giving error like "Time out". i add nearly 1 hour time out for overcome this. i know it is not a good practise but when i'm adding this it is working in local but not in server. in server it is givng error "Failure ending mail".suppose if i'm reduce time out to 10min ,its not giving any exception but not getting mail. i want to know i'm missing anything here ? is this server config problem..? please help me to sort this out

this is because of adding too many people at a time . try doing the same thing with your email on web browser and it will not allow you to send email.

To resolve this try making multiple groups out of 1000 emails like group of 100 or 200 and sending the mail to those groups.

NOTE 1) Check if firewall settings are off 2) Check if antivirus is installed, on sending email the antivirus asks to allow or not OR you could go in antivirus settings and disable the mail check options

I want to share my experience with sending emails.I also used to send B-Day emails but in my case there were usually 100-150 people and all mails delivered successfully. I had made a web service for this whose only task was to send emails. But before emails started to deliver successfully we tested on local machine which worked fine but when we tested it on server i face the same issue and cause of this failure was that we deployed our web service in .Net framework 2.0 than we changed it to 4.0 and tested it again with 10000,5000,1000 emails and it worked fine not all emails but most of them reached destination.Also one more thing to mention is that the address from which we were sending email was restricted by network department in email server to send only 100 emails.Also try to avoid sending too many emails from one sender and from one email server because you can get black listed.

Summary

  • First of all check that are you using .Net framework 2.0 if yes switch to 4.0.
  • Make sure that there are no restrictions by network department at email server and also to address which you use as sender.
  • Place all your code in using statement to make sure objects get disposed.
  • Send your emails in chunks(About 100 at a time).

    using() { //Place you email sending code here. }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM