从C#应用程序发送电子邮件问题 [英] sending e-mail from C# applications problem

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

问题描述

我在我的应用程序中包含此代码以将电子邮件发送给此类接收者,但出现以下错误:传输无法连接到服务器.

这是我的代码:

i have this code in my application to send an e-mail to such a receiver but i have the following error : The transport failed to connect to the server.

and here is my code :

System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage();
                       message.From = "some address";
                       message.To = txtEmail.Text;
                       message.Subject = "Message Subject";
                       message.Body = "Message Body";

System.Web.Mail.SmtpMail.SmtpServer = "the company exchange host server address";
System.Web.Mail.SmtpMail.Send(message);



在web.config中:



in the web.config :

<system.net>
  <mailsettings>
	<smtp deliverymethod="Network" from="sender address">
	  <network host="https://address" port="443" password="pass" username="user" defaultcredentials="true" />
        </smtp>
			
  </mailsettings>
</system.net>



如果有人可以在这个方面帮助我..因为我在其中进行了大量搜索,直到现在什么都没有发现:(



if some one can help me in this .. coz i searched a lot through this and found nothing till now :(

推荐答案

使用asp.net的SmtpMail错误:传输失败连接到服务器

原因:

当应用程序尝试发送电子邮件并且无法与SMTP服务器建立连接时,将显示此错误消息.
此问题的另一个原因是Smtp(虚拟)服务器的中继权限.

在大多数情况下,当我们需要使用除本地主机服务器(本地计算机)以外的另一台服务器作为smtp服务器时,会发生这种情况.有时它也会在本地计算机上引起问题.

然后,我们必须设置smtp服务器的中继权限.设置权限的步骤如下:

1.转到开始"->设置"->控制面板"->管理工具"-> IIS Maneger(Internet信息服务).

2.转到Internet信息服务-> Localhost(本地计算机)->. smtpserver.

3.右键单击smtp服务器,然后单击属性.

4.在属性对话框中...常规(选项卡)->检查本地计算机的名称和IP

如果列表为空,请单击高级".添加本地计算机IP和TCP端口25.

5.单击访问选项卡...单击中继

一个.选择仅以下列表(选项).
b.如果列表为空,请添加本地计算机IP.
C.如果要从网络的其他计算机发送邮件
还要添加该计算机IP,在列表中,您将看到已授予(IP)".
d.检查true允许所有计算机........

6.确定,然后应用(大声笑).

现在尝试使用System.Web.Mail.SmtpMail.SmtpServer ="127.0.0.1"(smtp服务器ip)...

我希望这会有所帮助.
(如果这确实对您有帮助,请投票给我解决方案)
Error SmtpMail with asp.net: Transport failed to connect to the server

Cause:

This error message will be displayed when the application is attempting to send email and is failing to establish a connection with the SMTP server.
Another cause of this problem is Relay Permission with Smtp (virtual) server.

Most of the cases this happens when we need to use another server as smtp server except localhost server (local computer). Sometimes it can make problem in local computer also.

Then we must set the relay permission of the smtp server. The following steps are to set the permission:

1. Go to Start->Settings->Control Panel->Administrative Tools->IIS Maneger (Internet Information Services).

2. Go to Internet Information Services->Localhost(local computer)-> smtpserver.

3. Right Click smtp server and click properties.

4. In properties dialog ... General (tab) -> Check Name and IP of local computer

Click Advance if list is blank Add local computer IP and TCP port 25.

5. Click on Access Tab... Click Relay

a. Select Only the list below (option).
b. if list is blank Add local computer IP.
c. if you want to send mail from other computer of the network
add that computer IP also and in list you will see Granted (IP).
d. check true allow all computer ........

6. Ok then Apply (lol).

Try the program now with System.Web.Mail.SmtpMail.SmtpServer = "127.0.0.1" (smtp server ip)...

I hope this will help.
(If this really helps you,Please vote for my solution)




您必须创建SmtpClient

hi

You have to create SmtpClient

SmtpClient smtp = new SmtpClient(SMTPServer);
smtp.Credentials = new NetworkCredential(SMTPUserName, SMTPPassword);
smtp.Send(mailMessage);




谢谢




Thanks
Joe



使用此命名空间


use this namespace

using System.Net.Mail;



示例代码:



sample code:

SmtpClient smtpClient = new SmtpClient();
           MailMessage message = new MailMessage();
           ArrayList frmempName = null;
           ArrayList toempName = null;
           sb.AppendLine();
           sb.Append(frmempName[0].ToString());
           message.Body = sb.ToString();
           message.From = new MailAddress(frmempName[2].ToString());
           message.Subject = "Sample Mail";
           smtpClient.Send(message);



在web.config设置中的邮件选项



in web.config settings for mail option

<system.net>
<mailSettings>
        <smtp>
        <network host="mail.net" port="587" userName="Admin" password="Adm!nn"/>
        </smtp>
    </mailSettings>
</system.net>



请检查.



please check.


这篇关于从C#应用程序发送电子邮件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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