149.xxx.xxx.xxx 是我的地址异常(C#、ASP.NET CORE 2.0、SMTP 客户端、MailKit)
149.xxx.xxx.xxx is my address exception (C#, ASP.NET CORE 2.0, SMTP-client, MailKit)
亲爱的同事们,大家好!
我正在尝试使用我同事创建的 SMTP 服务器发送电子邮件。我正在使用 .net core 2.0 这个身份。
当我 运行 我的应用程序在调试模式下使用我自己的计算机时 -- 它工作得很好。
当我 运行 托管它的同一个应用程序时,它会抛出此异常:
SmtpCommandException: 149.xxx.xxx.xxx is my address
MailKit.Net.Smtp.SmtpClient.OnSenderNotAccepted(MimeMessage message, MailboxAddress mailbox, SmtpResponse response)
主机和 smtp 服务器具有相同的 IP 地址并且在同一台计算机上工作。
我确定,“149.xxx.xxx.xxx 是我的地址”形式的异常意味着,smtp-server 认为,我是垃圾邮件发送者,试图将其 IP 用作 "whitelisted"——并且此服务器阻止我.
我找到了这个:
HELO is faked interface address
Type: forgery
Some spammers put the server's interface address they connect to in their HELO, maybe asuming it is whitelisted or something.
drop condition = ${if eq{[$interface_address]}{$sender_helo_name}}
message = $interface_address is my address
但同一主机有许多其他网络应用程序,它们与本地服务器的连接没有问题。
public async Task SendEmailAsync(string email, string subject, string message)
{
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX@XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX@XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
}
我尝试使用它的地址而不是 "localhost"。但它抛出相同的异常。
我应该怎么办?如何说我不是垃圾邮件制造者的 smtp 服务器,我只是物理上位于同一台计算机上的 IP 地址上?
是的,现在我做到了!
我需要使用直接连接到本地邮件服务器(没有 SMTP,这很重要)。
如何实现直连?我的 web-server 使用 Linux Ubuntu 系统。所以我需要使用 Shell(Ubuntu 终端)。
首先我手动测试了它:当我输入 "sendmail"(直接使用本地邮件服务器的命令)时,它需要收件人的电子邮件。
我需要在终端中输入:
$ sendmail xxx@mail.com
subject:My subject //这是新行
to:xxx@mail.com // 这是新行
from:kkk@mydomain.com // 这是新行
在这里我可以写很多行我的信正文。
. // 这是新行中的点(唯一的符号)以显示这是字母的结尾。下一个键盘"enter"表示最后发送
要使用这些命令,我需要创建新进程(与给出命令相同 "sendmail")。
所以,而不是这一切:
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX@XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX@XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
我刚插入
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "sendmail";
info.Arguments = $"{email}";
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("from:kkk@mydomain.com");
sw.WriteLine($"to:{email}");
sw.WriteLine($"subject:{subject}");
sw.WriteLine(message);
sw.WriteLine(".");
}
}
p.WaitForExit();
亲爱的同事们,大家好!
我正在尝试使用我同事创建的 SMTP 服务器发送电子邮件。我正在使用 .net core 2.0 这个身份。
当我 运行 我的应用程序在调试模式下使用我自己的计算机时 -- 它工作得很好。 当我 运行 托管它的同一个应用程序时,它会抛出此异常:
SmtpCommandException: 149.xxx.xxx.xxx is my address
MailKit.Net.Smtp.SmtpClient.OnSenderNotAccepted(MimeMessage message, MailboxAddress mailbox, SmtpResponse response)
主机和 smtp 服务器具有相同的 IP 地址并且在同一台计算机上工作。 我确定,“149.xxx.xxx.xxx 是我的地址”形式的异常意味着,smtp-server 认为,我是垃圾邮件发送者,试图将其 IP 用作 "whitelisted"——并且此服务器阻止我.
我找到了这个:
HELO is faked interface address
Type: forgery
Some spammers put the server's interface address they connect to in their HELO, maybe asuming it is whitelisted or something.
drop condition = ${if eq{[$interface_address]}{$sender_helo_name}}
message = $interface_address is my address
但同一主机有许多其他网络应用程序,它们与本地服务器的连接没有问题。
public async Task SendEmailAsync(string email, string subject, string message)
{
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX@XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX@XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
}
我尝试使用它的地址而不是 "localhost"。但它抛出相同的异常。 我应该怎么办?如何说我不是垃圾邮件制造者的 smtp 服务器,我只是物理上位于同一台计算机上的 IP 地址上?
是的,现在我做到了!
我需要使用直接连接到本地邮件服务器(没有 SMTP,这很重要)。
如何实现直连?我的 web-server 使用 Linux Ubuntu 系统。所以我需要使用 Shell(Ubuntu 终端)。
首先我手动测试了它:当我输入 "sendmail"(直接使用本地邮件服务器的命令)时,它需要收件人的电子邮件。
我需要在终端中输入:
$ sendmail xxx@mail.com subject:My subject //这是新行 to:xxx@mail.com // 这是新行 from:kkk@mydomain.com // 这是新行
在这里我可以写很多行我的信正文。 . // 这是新行中的点(唯一的符号)以显示这是字母的结尾。下一个键盘"enter"表示最后发送
要使用这些命令,我需要创建新进程(与给出命令相同 "sendmail")。
所以,而不是这一切:
var emailMessage = new MimeMessage();
emailMessage.From.Add(new MailboxAddress("No reply", "XX@XXXX.XXX"));
emailMessage.To.Add(new MailboxAddress("", email));
emailMessage.Subject = subject;
emailMessage.Body = new TextPart(MimeKit.Text.TextFormat.Html)
{
Text = message
};
using (var client = new SmtpClient())
{
await client.ConnectAsync("localhost", 25, SecureSocketOptions.None);
await client.AuthenticateAsync("XX@XXXX.XXX", "Password");
await client.SendAsync(emailMessage);
await client.DisconnectAsync(true);
}
我刚插入
Process p = new Process();
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "sendmail";
info.Arguments = $"{email}";
info.RedirectStandardInput = true;
info.UseShellExecute = false;
info.CreateNoWindow = true;
p.StartInfo = info;
p.Start();
using (StreamWriter sw = p.StandardInput)
{
if (sw.BaseStream.CanWrite)
{
sw.WriteLine("from:kkk@mydomain.com");
sw.WriteLine($"to:{email}");
sw.WriteLine($"subject:{subject}");
sw.WriteLine(message);
sw.WriteLine(".");
}
}
p.WaitForExit();