SMTP邮件发送服务器名称与发件人电子邮件不同

时间:2020-07-30 11:01:51

标签: c# asp.net-mvc c#-4.0 smtp smtpclient

我被困在SMTP服务器使用不同名称而发件人电子邮件使用不同名称的情况下。

SMTP Server :- mail.in.xyz.com
Sender :- hrd@in.xyz.com

您可以在此处注意到,服务器是mail.in.xyz.com,发件人域是@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);

关于如何解决这个问题的任何想法?

1 个答案:

答案 0 :(得分:0)

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);
        }
    }
}