I'm currently developing an application where a file is downloaded from a server, attaches it to an email and sends it to the entered gmail-address. The first time I tried it, it worked fine. When I tried it the second time, the hanging begun, and it hasn't worked since.
Here is my code:
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
MailMessage mail = new MailMessage();
mail.From = new MailAddress(fran);
mail.To.Add(till);
mail.Subject = amne;
mail.Body = text;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("file.txt");
mail.Attachments.Add(attachment);
SmtpServer.Port = 465;
SmtpServer.Timeout = 30000;
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(user, pw);
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
SmtpServer.Dispose();
mail.Dispose();
I've tried ports 587, 465 and 25 aswell as opening them in the Windows Firewall. I've tried disabling Avast! AntiVirus, running as administrator and restarting my computer. Running once and only once makes me think its some kind of caching issue, but what?
I appreciate all tips and suggestions, fire away!
Thanks in advance, Fredrik