简体   繁体   English

C#SMTP发送问题?

[英]c# smtp sending problems?

I'm having problem sending an attachment via email using smtp client. 我在使用smtp客户端通过电子邮件发送附件时遇到问题。 It sends great on my computer and a friends computer. 它在我的计算机和朋友计算机上发送效果很好。 But 2 other friend computers are having problems sending the file. 但是其他两台朋友计算机在发送文件时遇到问题。 I thought the problem would be the port as I've read elsewhere that some ISP's block port 25 so I've changed the port to 2525, although that does not fix my problem. 我以为问题是端口,因为我在其他地方读过一些ISP的阻塞端口25,所以我将端口更改为2525,尽管那不能解决我的问题。 They get the same error - Error sending message. 他们得到相同的错误-发送消息错误。

Code provided below - 下面提供的代码-

        MailMessage message = new MailMessage();
        try
        {
            SmtpClient client = new SmtpClient("smtp.live.com", 2525);
            client.EnableSsl = true;
            client.Credentials = new NetworkCredential("accoutn@account.com", "abc123");

            MailAddress senderAddress = new MailAddress("DoNotReply@live.com");
            Attachment attach = new Attachment(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + "\\" + doc.getFirstName() + doc.getSurname() + ".doc");
            message.From = senderAddress;
            message.Subject = "Physio Information";
            message.Attachments.Add(attach);

            message.To.Add("sendmessageto@something.com");
            message.Body = "Physio Report of " + doc.getFirstName() + " " + doc.getSurname();

            client.Send(message);
            MessageBox.Show("Information Processed");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            failMail = true;
        }
        finally
        {
            message.Dispose();
        }

You must use an alternate port designated by the mail providor. 您必须使用邮件提供者指定的备用端口。 I believe live mail uses port 587. Give that a shot. 我相信实时邮件使用端口587。试试吧。

Go to the email provider's website and find out the alternate smtp port. 转到电子邮件提供商的网站,并找到备用的smtp端口。 All of them have one or ten. 他们都有一到十个。 That is the most likely culprit. 那是最可能的罪魁祸首。 25 is almost always blocked on a residential line. 25几乎总是在住宅线路上被阻塞。

You cannot change the port to 2525 at will. 您不能随意将端口更改为2525 smtp.live.com is connectable on port 25 (unless some other documented) and hence only port 25 can be used. smtp.live.com可在port 25port 25 (除非有其他文档说明),因此只能使用port 25 You can verify using telnet as follows 您可以按以下方式使用telnet进行验证

telnet smtp.live.com 25

Check the firewall on your friend's computer, they might be blocking outgoing port 25 . 检查朋友计算机上的防火墙,它们可能阻止了传出port 25 Also check if you are able to telnet on those computers by typing above command. 还要通过键入上述命令来检查是否能够在这些计算机上进行telnet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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