- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
以下代码,在.net core 2
环境下编写,在windows环境
下运行,在linux环境下运行
。
string host = "10.99.99.10";
int port = 25;
string userName = "user@user.com";
string password = "password";
string from = userName;
var client = new SmtpClient
{
Host = host,
Port = port,
EnableSsl = false,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new NetworkCredential(userName, password)
};
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(from);
mailMessage.To.Add(userName);
mailMessage.Body = "This is test mail.";
mailMessage.Subject = "Testing";
client.Send(mailMessage);
异常:发送邮件失败。
内部异常:
System.ComponentModel.Win32Exception (0x80004005): GSSAPI operation failed with error - An invalid status code was supplied (Unknown error).
at System.Net.Security.NegotiateStreamPal.AcquireCredentialsHandle(String package, Boolean isServer, NetworkCredential credential)
at System.Net.NTAuthentication.Initialize(Boolean isServer, String package, NetworkCredential credential, String spn, ContextFlagsPal requestedContextFlags, ChannelBinding channelBinding)
at System.Net.Mail.SmtpNtlmAuthenticationModule.Authenticate(String challenge, NetworkCredential credential, Object sessionCookie, String spn, ChannelBinding channelBindingToken)
at System.Net.Mail.SmtpConnection.SetContextAndTryAuthenticate(ISmtpAuthenticationModule module, NetworkCredential credential, ContextAwareResult context)
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)
堆栈跟踪:
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at MyProject.Helper.Utils.SendMail() in C:\Test\MyProject\MyProject.Helper\Utils.cs:line 146
Linux:Ubuntu 16.04.3 LTS
这是一个控制台应用程序。为什么不能在 linux 环境下工作?
最佳答案
因为我的错误,我以为是代码错误,其实不是。当我在邮件服务器端授予 relay authority
时,我的问题就解决了。我认为它会在 Windows 环境中自动执行此操作。
编辑:在接收连接器/Exchange 服务器中添加 IP 地址并允许匿名用户
关于c# - SmtpClient.Send 不适用于 linux 环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46639787/
我正在尝试从本地主机发送邮件.. 在执行此操作时,我有来自不同站点的方法来发送邮件..但是在执行此操作时,我对 smtpClient.send() 感到困惑和smtpClient.SendAsync(
我正在从事一个项目(不幸的是)需要允许的最大框架是 .NET 4。 在这个项目中,我尝试使用 SendAsync() 异步发送电子邮件,但由于某种原因,它发送失败(或者更确切地说,它只是不发送)。简单
考虑到 SmtpClient 有一个我没有使用的 SendAsync 方法,因此假设 StmpClient.Send 是同步的是否安全?我用它来发送带有临时文件附件的电子邮件,想知道我是否可以在之后立
我在多台(不是说:所有)Windows 8.x 机器上面临以下问题: 运行这段代码: var message = new MailMessage(); message.From = new MailA
如标题所述,将“SmtpClient::EnableSsl”设置为 true 的“System::Net::Mail::SmtpClient”需要哪些端口? documentation on the
如果我已将一些电子邮件排队等待通过 System.Net.Mail.SMTPClent 发送,我在哪里可以找到这封邮件?对于 Windows SMTP 客户端,它位于 C:\inetpub\mailr
.NET SmtpClient 对象中的超时默认值是多少?它是什么时间单位(秒、毫秒等)? 最佳答案 默认值为 100,000(100 秒)。 http://msdn.microsoft.com/en
我尝试使用 SmtpClient.Send() 从 c# 发送电子邮件,但它总是进入垃圾箱。如果我从 Outlook 发送它,它工作正常。无论如何要解决这个问题?有人告诉我修改电子邮件标题,但我不知道
我正在尝试使用 C# 创建一个小型应用程序来发送电子邮件,但即使使用端口 587 (GMail) TLS 或 465 (GMail SSL) 我也无法让它工作。我不确定是什么导致了我的问题,我应该编辑
当我使用 SmtpClient 发送电子邮件时,我发现了一个奇怪的行为: 送货时间太长。 已送达两次。 SmtpClient client = new SmtpClient(); client.Hos
我正在使用以下代码发送电子邮件: using (var mailMessage = new MailMessage("from@example.com", "to@example.com")) {
我遇到了一个让我抓狂的问题!!!我有一个用于发送电子邮件的小型 Delphi 7 应用程序(使用 Indy 9 组件套件)并且一切正常。我正在尝试开发一个执行相同操作的 C# 应用程序 (Visual
我的 Smtpclient 正在使用以下设置 SmtpClient client = new SmtpClient(); client.Host = server; client.UseDefault
我的问题是:我需要发现一个 IP 和端口是否正在运行 SMTP 服务。为此,我使用 SMTPClient 尝试打开连接。我正在使用下面的代码。 private static boolean v
我有一个指向我公司邮件服务器的 SmtpClient。我能够成功地向/从该域上的地址发送电子邮件。 但是,我需要为应用程序的用户重置密码和通知。这些用户使用他们自己的电子邮件地址(多个不同的域)注册。
SmtpClient 发送方法返回无效。有什么办法可以得到服务器响应吗?我是否只是假设它是成功的,除非它抛出异常? 我指的是类... http://msdn.microsoft.com/en-us/l
我正在创建每 5 分钟发送一批电子邮件的 Windows 服务。 我想每 5 分钟发送 10-100 封电子邮件。这是极端情况。每 5 分钟发送一次批处理,通常最多包含 10 封电子邮件。 我正在使用
我已经设置了 SmtpClient 类的超时属性,但它似乎不起作用,当我给它一个 1 毫秒的值时,执行代码时超时实际上是 15 秒。我从 msdn 中获取的代码. string to = "jane@
我正在从 Java 向我们的客户发送电子邮件。而且我们的 SMTP 没有任何身份验证。因此,我在 Java 中使用以下代码无需身份验证即可发送: Properties props = new Prop
我有一个 C# 服务 那个连续运行 使用用户凭据(即不是本地系统 - 虽然我想更改但我无法更改)。在大多数情况下,该服务似乎运行正常,但它经常爆炸和 无故重启 (服务管理器设置为在崩溃时重新启动服务)
我是一名优秀的程序员,十分优秀!