c# - SMTP 邮件发送服务器名称与发件人电子邮件不同
问题描述
我陷入了 SMTP 服务器名称不同且发件人电子邮件名称不同的情况。
SMTP Server :- mail.in.xyz.com
Sender :- hrd@in.xyz.com
您可以在这里注意到 Server ismail.in.xyz.com
和 Sender domain@in.xyz.com
都是不同的。
它给出了一个错误: -
System.Net Information: 0 : [15384] SecureChannel#57667028 - Remote certificate has errors:
System.Net Information: 0 : [15384] SecureChannel#57667028 - A certificate chain processed,
but terminated in a root certificate which is not trusted by the trust provider.
当它被转发给客户端时:- 错误文件是指自签名的证书之一(in.xyz.com)。但它需要引用另一个证书,即 XYZ 信任的 mail.in.xyz.com。由于它指的是自签名,因此发生了日志文件中提到的错误。
我正在使用以下代码发送邮件。
SmtpClient smtp = new SmtpClient
{
Host = data.SMTPServer, // smtp server address here...
Port = data.PortNo,
EnableSsl = data.SSL,
DeliveryMethod = SmtpDeliveryMethod.Network,
UseDefaultCredentials = false,
Credentials = new System.Net.NetworkCredential(senderID, senderPassword),
Timeout = 30000,
};
smtp.Send(message);
关于如何解决这个问题的任何想法?
解决方案
public class Email
{
private const string fromEmail = "mail@site.com";
private const string webEmail = "webmail.site.com";
private const string password = "Y2";
// Email.Send("x@gmail.com", "blah blah", "HIIIIIIIIIIIIIIIIIIII");
public static void Send(string to, string subject, string body)
{
try
{
var message = new MailMessage
{
From = new MailAddress(fromEmail),
To = { to },
Subject = subject,
Body = body,
DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure
};
using (SmtpClient smtpClient = new SmtpClient(webEmail))
{
smtpClient.Credentials = new NetworkCredential(fromEmail, password);
smtpClient.Port = 25;
smtpClient.EnableSsl = false;
smtpClient.Send(message);
}
}
catch (Exception excep)
{
throw new Exception(excep.Message);
}
}
}
推荐阅读
- java - 如何使用 JPA Hubernate 将 EntityManager 注入 DAO 或 Servlet
- python - Python从日期列行中删除包含字符串
- javascript - Puppeteer 在指定时间安排动作
- pyspark - 将矩阵转换为 Pyspark 数据框
- azure-api-management - 将本地 LDAP 配置到 Azure API 管理器?
- javascript - 当您从逻辑中知道类型正确时,如何“修复”流类型?
- python - 如何在任意点绘制抛物线的斜率(切线)?
- ruby - Ruby:为什么每当 `#eql?` 被覆盖时,`#hash` 需要被覆盖?
- javascript - Vue组件模板部分的递归?
- gradle - Hyperledger:使用 Gradle 构建链码