config.yaml
知道我为什么会收到错误
无法解析远程名称。
显然,由于我指定了IP地址,因此无需解析。我可以在端口25上ping IP甚至telnet并成功发送电子邮件。但是,我无法发送电子邮件。
我运行了# top
跟踪,看起来没有任何流量发送到172.22.0.20
答案 0 :(得分:8)
我使用此代码,并且它在我的最终工作正常 确保使用正确的IP地址和端口号。我认为您的端口号不正确。 (打开您的电子邮件ID并检查邮件配置)
MailMessage mail = new MailMessage("bob@internalhost.com", "Toemai@email.com");
mail.Subject = "Subject";
mail.IsBodyHtml = true;
mail.Body = "this is email body";
SmtpClient client = new SmtpClient("172.22.0.20");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("bob@internalhost.com", "password");
client.Port = 25;
client.Send(mail);
答案 1 :(得分:3)
我用以下代码测试了你的代码:
static void Main(string[] args)
{
try
{
MailMessage message = new MailMessage();
message.Subject = "test";
message.Body = "test";
message.To.Add("atmane.elbouachri@gmail.com");
message.From = new MailAddress("atmane.elbouachri@softeam.fr");
SmtpClient smtp = new SmtpClient();
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.UseDefaultCredentials = false;
smtp.Host = "127.0.0.1";
smtp.Port = 25;
smtp.Send(message);
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
}
看起来不错。我使用了smtp4dev工具,它就是这个:
220 localhost smtp4dev ready
EHLO Aepro
250-Nice to meet you.
250-8BITMIME
250-STARTTLS
250-AUTH=CRAM-MD5 PLAIN LOGIN ANONYMOUS
250-AUTH CRAM-MD5 PLAIN LOGIN ANONYMOUS
250 SIZE
MAIL FROM:<atmane.elbouachri@softeam.fr>
250 Okey dokey
RCPT TO:<atmane.elbouachri@gmail.com>
250 Recipient accepted
RSET
250 Rset completed
RSET
250 Rset completed
MAIL FROM:<atmane.elbouachri@softeam.fr>
250 Okey dokey
RCPT TO:<atmane.elbouachri@gmail.com>
250 Recipient accepted
DATA
354 End message with period
MIME-Version: 1.0
但是当我放假IP时我有一个例外(女巫是正常的)。
我认为您的IP不好或者您必须遇到防火墙问题
答案 2 :(得分:3)
下面的代码工作正常......
[![<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style>
#sidebar-wrapper{ width:500px; height:500px;border-radius: 50%;margin-left: -25%; background:#183343; margin-top: 67px;}
.new-con a {
font-size: 30px;
color: #fff !important;
margin-left: 30px;
display: block;
}
.dashboard-icon.new-con {
position: absolute;
margin-left: 394px;
margin-top: 229px;
}
.user-div.new-con{ margin-left: 382px;
position: absolute;
margin-top: 312px;}
.inner-border{ background:url(icon/new1.png);}
.cog-icon.new-con {
margin-top: 393px;
position: absolute;
margin-left: 336px;
}
.dasbord-icon-inner {
background: url(icon/das-black.png);
width: 32px;
height: 32px;
background-size: 32px 32px !Important;
background-repeat: no-repeat;
}
#sidebar-wrapper {
position: relative;
}
.dasbord-icon-inner{ background:url(icon/das-black.png);}
.time-icon.new-con {
margin-top: 152px;
position: absolute;
margin-left: 378px;
}
/* Calender Icon Start */
.calender-div.new-con {
margin-top: 84px;
position: absolute;
margin-left: 340px;
}
.calender-div .inner-border {
background: url(icon/new1.png);
width: 43px;
height: 45px;
margin-left: 15px;
position: absolute;
top: -31px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(-47deg); display:none;
}
.calender-div:hover .dasbord-icon-inner {
background: url(icon/das-white.png);
z-index: 10;
position: relative;
}
.calender-div:hover .inner-border{ display:block;}
.calender-div .inner-con{
margin-left: 44px;
position: absolute;
top: -70px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(-47deg);
display: none;
color: #000;
font-size: 20px;}
.calender-div:hover .inner-con{ display:block;}
/* Calender Icon end */
/* Calender Icon Start */
.time-icon .inner-border {
background: url(icon/new1.png);
width: 43px;
height: 45px;
margin-left: 32px;
position: absolute;
top: -25px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(-24deg); display:none;
}
.time-icon:hover .dasbord-icon-inner {
background: url(icon/das-white.png);
z-index: 10;
position: relative;
}
.time-icon:hover .inner-border{ display:block;}
.time-icon .inner-con{
margin-left: 82px;
position: absolute;
top: -46px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-23deg);
transform: rotate(-23deg);
display: none;
color: #000;
font-size: 20px;}
.time-icon:hover .inner-con{ display:block;}
/* Calender Icon end */
/* Dasbord Icon */
.dashboard-icon .inner-border {
background: url(icon/new1.png);
width: 43px;
height: 45px;
margin-left: 40px;
position: absolute;
top: -15px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(-4deg); display:none;
}
.dashboard-icon:hover .dasbord-icon-inner {
background: url(icon/das-white.png);
z-index: 10;
position: relative;
}
.dashboard-icon:hover .inner-border{ display:block;}
.dashboard-icon .inner-con{
margin-left: 94px;
position: absolute;
top: -13px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-23deg);
transform: rotate(-4deg);
display: none;
color: #000;
font-size: 20px;}
.dashboard-icon:hover .inner-con{ display:block;}
/* Dasbord Icon end */
/* User Icon */
.user-div .inner-border {
background: url(icon/new1.png);
width: 43px;
height: 45px;
margin-left: 31px;
position: absolute;
top: 11px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(21deg);
display: none;
}
.user-div:hover .dasbord-icon-inner {
background: url(icon/das-white.png);
z-index: 10;
position: relative;
}
.user-div:hover .inner-border{ display:block;}
.user-div .inner-con{
margin-left: 82px;
position: absolute;
top: 36px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-23deg);
transform: rotate(14deg);
display: none;
color: #000;
font-size: 20px;}
.user-div:hover .inner-con{ display:block;}
/* User Icon end */
/* Last Icon */
.cog-icon .inner-border {
background: url(icon/new1.png);
width: 43px;
height: 45px;
margin-left: 15px;
position: absolute;
top: 12px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-47deg);
transform: rotate(47deg);
display: none;
}
.cog-icon:hover .dasbord-icon-inner {
background: url(icon/das-white.png);
z-index: 10;
position: relative;
}
.cog-icon:hover .inner-border{ display:block;}
.cog-icon .inner-con{
margin-left: 57px;
position: absolute;
top: 82px;
-webkit-transform: rotate(-47deg);
-moz-transform: rotate(-47deg);
-o-transform: rotate(-47deg);
-ms-transform: rotate(-23deg);
transform: rotate(38deg);
display: none;
color: #000;
font-size: 20px;
width: 100px;}
.cog-icon:hover .inner-con{ display:block;}
/* Last Icon end */
</style>
</head>
<body>
<div id="sidebar-wrapper">
<div class="calender-div new-con">
<a href="#"><div class="dasbord-icon-inner"></div>
<div class="inner-border"></div>
<div class="inner-con">Calander</div>
</a>
</div>
<div class="time-icon new-con">
<a href="#">
<div class="dasbord-icon-inner"></div>
<div class="inner-border"></div>
<div class="inner-con">Alarm</div>
</a>
</div>
<div class="dashboard-icon new-con">
<a href="#">
<div class="dasbord-icon-inner"></div>
<div class="inner-border"></div>
<div class="inner-con">Dasbord</div>
</a>
</div>
<div class="user-div new-con">
<a href="#">
<div class="dasbord-icon-inner"></div>
<div class="inner-border"></div>
<div class="inner-con">Uesr</div>
</a>
</div>
<div class="cog-icon new-con">
<a href="#">
<div class="dasbord-icon-inner"></div>
<div class="inner-border"></div>
<div class="inner-con">Last Icon</div>
</a>
</div>
</div>
</body>
</html>][1]][1]
答案 3 :(得分:2)
如果您的代码在服务应用程序池中运行 - 您需要在流程模型中将高级设置下的标识设置为&#34;网络服务&#34;而不是默认的&#34; ApplicationPoolIdentity&#34;。如果你这样做,它每次都会工作。如果你没有,有些电子邮件可以使用,有些则没有。这是一个奇怪的许可事情。
答案 4 :(得分:1)
此处出现了类似的问题:System.Net.WebException: The remote name could not be resolved:
正如您所看到的,围绕try-catch语句的简单轮询机制可以让您有机会在向用户报告之前多次尝试您的方法块(偶尔会失败)。
答案 5 :(得分:0)
我看到的问题是这一行:
number
smtp.Host需要字符串。所以,它应该是smtp.Host = 172.22.0.20;
除此之外,请添加以下代码,以便我们看到错误
smtp.Host = "172.22.0.20";
答案 6 :(得分:0)
您的IP地址不正确,或者您可能正在防火墙下工作。另请检查DNS设置。
答案 7 :(得分:0)
也许反向名称是强制性的,您是否尝试在主机文件中注册此IP的名称? (或者当然在您的DNS中)
尝试添加:
172.22.0.20 my-smtp.example