Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have this exception when sending mail
the operation has timed out
any help
this is my code
C#
protected bool SendMail()
        {
            //MessageBox.Show(plainText);
            bool send = true;
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
                mail.From = new MailAddress(fromMail);
                //mail.To.Add(email);


                var distinctAddress = new List<string>(email.Split(',').Distinct());
                //mail.To = string.Empty;

                foreach (string address in distinctAddress) // Loop through all strings
                {
                    mail.To.Add(address) ;//= address + ","; 
                    emailsList.Add(address);
                }
                //this.To = this.To.TrimEnd(',');
                //mail.To.Add(this.To);

                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                //if (!String.IsNullOrWhiteSpace(filePath))
                if(filesPathList.Count > 0)
                {
                    for (int i = 0; i < filesPathList.Count; i++)
                    {
                        mail.Attachments.Add(new Attachment(filesPathList[i]));
                    }
                }

                if (uploadsPathList.Count > 0)
                {
                    for (int i = 0; i < uploadsPathList.Count; i++)
                    {
                        mail.Attachments.Add(new Attachment(uploadsPathList[i]));
                    }
                }
                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential(fromMail, fromPass);
                SmtpServer.EnableSsl = true;
                SmtpServer.Send(mail);
                
            }
            catch (Exception ex)
            {
                send = false;
                MessageBox.Show(ex.ToString());
            }
            return send;
        }

..
Posted
Updated 31-Jul-17 20:48pm
Comments
Mathi Mani 5-Jun-15 20:11pm    
It seems you are trying to send too many attachments in one email. That may be the reason. Try sending with 1 or 2 attachment and see if it works.
ZurdoDev 6-Jun-15 21:59pm    
Please post as solution.
Heba Kamel 5-Jun-15 20:31pm    
you are right, I tried 2 or 3 and it's sending correctly
the question now how many attachment can I send ?
Sergey Alexandrovich Kryukov 5-Jun-15 20:58pm    
More likely, it's not the number of "attachments" (parts), but the total size.
—SA
Heba Kamel 5-Jun-15 21:10pm    
any way to increase this size to send more attachments ?

1 solution

Sorry to be bearer of bad news, GMAIL has limits on
a) total message size
b) individual attachment size
c) total number of attachments

Apparently, these can be bypassed if the attachments are stored in google drive and the attachments are merely links to the google drive storage though I
a) don't use any cloud storage for business confidential files
b) know how to attach such links

If you really require to beat the default limits you need to read up on these limits and bypasses in places like Send attachments with your Gmail message - Computer - Gmail Help[^]

Sorry, I only just noticed the age of this. Way tooooo late :-)
 
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