4

我正在使用 asp.net c# 发送电子邮件。除了回复,一切都很完美。我正在设置回复并将电子邮件发送给自己。在电子邮件客户端(即gmail)中,回复是正确的,但回复是发给电子邮件发件人的,而不是我分配的备用回复。这是我的代码:

public void SendEmail(string subject, string body, string to, string reply,string replytoname, int nameID)
{
    MailAddress Sender = new MailAddress("sender@mydomain.com", "sender name", System.Text.Encoding.UTF8);
    MailAddress Receiver = new MailAddress(to);
    MailAddress Reply = new MailAddress(reply, replytoname, System.Text.Encoding.UTF8);
    MailMessage msg = new MailMessage(Sender, Receiver);
    msg.Subject = subject;
    msg.SubjectEncoding = System.Text.Encoding.UTF8;
    msg.BodyEncoding = System.Text.Encoding.UTF8;
    msg.IsBodyHtml = true;
    msg.ReplyTo = Reply;
    msg.Body = body;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.mydomain.com";
    smtp.Port = 25;
    smtp.EnableSsl = true;
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new NetworkCredential("sender@mydomain.com", "password");
    ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
    smtp.Send(msg);
} 

在此处输入图像描述

4

0 回答 0