公司内网邮件发送问题!
我引用大侠的代码还是出问题,主要代码如下:
1using System;
2using System.Data;
3using System.Configuration;
4using System.Web;
5using System.Web.Security;
6using System.Web.UI;
7using System.Web.UI.WebControls;
8using System.Web.UI.WebControls.WebParts;
9using System.Web.UI.HtmlControls;
10using System.Net.Mail;
11using System.Net;
12
13public partial class _Default : System.Web.UI.Page
14{
15 protected void Button1_Click(object sender, EventArgs e)
16 {
17 MailMessage message = new MailMessage("support@vs2005.com", "to@domain.com");
18 message.Subject = "hello!";
19 message.Body = "this is a mail from vs2005.com";
20
21 SmtpClient smtp = new SmtpClient("smtp.vs2005.com");
22 smtp.Credentials = new MailCredential("username", "userpassword");
23 smtp.Send(message);
24 }
25}
26
27public class MailCredential : ICredentialsByHost
28{
29 string username = "";
30 string userpwd = "";
31
32 public MailCredential(string un, string pwd)
33 {
34 username = un;
35 userpwd = pwd;
36 }
37
38 ICredentialsByHost Members#region ICredentialsByHost Members
39
40 public NetworkCredential GetCredential(string host, int port, string authenticationType)
41 {
42 NetworkCredential nc = new NetworkCredential(username, userpwd);
43 return nc;
44 }
45
46 #endregion
47}
出错信息如下:
No connection could be made because the target machine actively refused it
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
Source Error:
Line 25: SmtpClient smtp = new SmtpClient("156.5.80.44");
Line 26: smtp.Credentials = new MailCredential("hong-tao.liu@unilever.com", "P@ssw0rd");
Line 27: smtp.Send(message);
Line 28:
Line 29: }
请问用(c#)vs 2005 asp.net怎么实现企业内网邮件的发送呀?
还请各位大侠多多指点!!