从交换服务器发送电子邮件 [英] Sending an email from exchange server

查看:102
本文介绍了从交换服务器发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经编写了一个代码,可以在其中使用交换服务器发送电子邮件.
但是在执行时会抛出错误,如

代码开始

Hi,

I have written a code where in I am sending an email using an exchange server.
But while execution it throws an error as

code start

MailMessage mail = new MailMessage();
         mail.To.Add("testuser2@company.com");
         mail.From = new MailAddress("testuser1@company.com");
         mail.Subject = "Test Email";
         string Body = "BODY of email";
         mail.Body = Body;
         SmtpClient smtp = new SmtpClient();
         smtp.Host = "exchange_server name">;//ConfigurationManager.AppSettings["SMTP"];
         smtp.Send(mail);




代码结尾

错误如下:-




Code end

Below is the error:-

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it ip_address:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) 



请帮助我.
还请让我知道是否需要请我们的网络团队授予我的用户ID的权限,该用户ID在这里用作ID,以便从交换服务器进行身份验证?

亲切的问候,
Satwinder singh



Kindly help me.
Also let me know whether I need to do ask our network team to give rights to my user ID which is used here in as from Id to authenticate from exchange server?

Kind Regards,
Satwinder singh

推荐答案

最好的方法是在防火墙上未打开smtp端口时向有效的交换用户进行身份验证.
your best way is authenticating with a valid exchange user when smtp port is not open on firewall.


可以您通过telnet交换服务器?它在错误中说:无法建立连接,因为目标计算机主动拒绝了它ip_address:25.因此,或者交换服务器未使用端口25发送邮件,或者不允许您从您所在的位置访问服务器.最好与网络管理员联系,谁可以告诉您这两个错误中的哪一个.
can you telnet your exchange server? It says in the error: No connection could be made because the target machine actively refused it ip_address:25. So or the exchange server uses not port 25 for sending mails or you are not allowed to reach the server as from the location where you are. Better talk to the networkadmin who can tell you which of the 2 is wrong.


SmtpClient serverobj = new SmtpClient();
serverobj.Credentials = new NetworkCredential("youremail id","yourpassword");
serverobj.Port = 587;
serverobj.Host ="smtp.gmail.com";
serverobj.EnableSsl = false;
obj =新的System.Net.Mail.MailMessage();
obj.From = new MailAddress("anilmeets4u@gmail.com","AgileLearning.com",System.Text.Encoding.UTF8);
obj.To.Add(ASPxtxtToUser.Text);
obj.CC.Add(txtCcUser.Text);
obj.Priority = System.Net.Mail.MailPriority.High;
obj.Subject = txtSubject.Text;
字符串日期= DateTime.Now.ToString();
obj.Body = ASPxMemo1.Text;
serverobj.Send(obj);


试试这个........它将起作用


问候,
Anilkumar.D
SmtpClient serverobj = new SmtpClient();
serverobj.Credentials = new NetworkCredential("youremail id", "yourpassword");
serverobj.Port = 587;
serverobj.Host = "smtp.gmail.com";
serverobj.EnableSsl = false;
obj = new System.Net.Mail.MailMessage();
obj.From = new MailAddress("anilmeets4u@gmail.com", "AgileLearning.com", System.Text.Encoding.UTF8);
obj.To.Add(ASPxtxtToUser.Text);
obj.CC.Add(txtCcUser.Text);
obj.Priority = System.Net.Mail.MailPriority.High;
obj.Subject = txtSubject.Text;
string date = DateTime.Now.ToString();
obj.Body = ASPxMemo1.Text;
serverobj.Send(obj);


Try this........ it will work


Regards,
Anilkumar.D


这篇关于从交换服务器发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆