3

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

4

2 回答 2

1

您的代码有效,问题是您使用了错误的端口。您必须使用端口 587

于 2013-10-24T18:39:52.370 回答
0

我正在尝试使用 Powerbuilder 发送 smtp 邮件,但遇到了同样的挂起情况。不确定它是否对 C++ 平台有帮助,但我为解决该问题所做的是放置更新版本的 cl32.dll(当然,谈论 Windows)。

于 2013-12-24T18:53:09.167 回答