开发者

c# smtp sending problems?

I'm having problem sending an attachment via email using smtp client. 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. 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)
        {
            Message开发者_运维问答Box.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.


Go to the email provider's website and find out the alternate smtp port. All of them have one or ten. That is the most likely culprit. 25 is almost always blocked on a residential line.


You cannot change the port to 2525 at will. smtp.live.com is connectable on port 25 (unless some other documented) and hence only port 25 can be used. You can verify using telnet as follows

telnet smtp.live.com 25

Check the firewall on your friend's computer, they might be blocking outgoing port 25. Also check if you are able to telnet on those computers by typing above command.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜