MAILKIT 更改消息。来自

问题描述 投票:0回答:2

我需要更改消息(smtpClient 对象)中的

"message.From.Add(New MailboxAddress(sendername, senderemail)" 

已经准备好另一个功能了

"message.From.Add(New MailboxAddress(sendername, othersenderemail)"

有什么建议吗?

非常感谢

vb.net mailkit
2个回答
1
投票

我的猜测是,您想问的是如何从

[email protected]
发送电子邮件,但发件人标题为
[email protected]
(或类似的)。

您有 2 个选择:

  1. 您可以将

    message.Sender
    设置为您实际想要发送的地址,同时将
    message.From
    设置为您希望消息显示的发件人地址。这具有在消息中添加
    Sender: My Name <[email protected]>
    标头的副作用,该标头可能是也可能不是您关心的内容。

  2. 您可以使用

    SmtpClient.Send(MimeMessage message, MailboxAddress sender, IEnumerable<MailboxAddress> recipeints, CancellationToken cancellationToken)
    API,它不会更改 MimeMessage 的标头。

例如:

var message = new MimeMessage ();
message.From.Add (new MailboxAddress (string.Empty, "[email protected]"));
message.To.Add (new MailboxAddress ("Customer Name", "[email protected]"));
message.Subject = "Your order is on its way!";
message.Body = GenerateMessageBody ();

using (var client = new SmtpClient ()) {
    client.Connect ("smtp.mycompany.com", 587, SecureSocketOptions.StartTls);
    client.Authenticate ("[email protected]", "password");

    var sender = new MailboxAddress (string.Empty, "[email protected]");

    // This API is new in MimeKit v3.0, but will collect the unique email 
    // addresses in the To, Cc, and Bcc fields into 1 collection.
    var recipients = message.GetRecipients (true);

    // Send the message from your account w/o having to modify the From header.
    client.Send (message, sender, recipients);

    client.Disconnect (true);
}

0
投票

我也在尝试做类似的事情,我希望发件人地址[电子邮件受保护],但递送失败报告应发送到特定电子邮件地址,例如[电子邮件受保护]。我怎样才能做到这一点?

© www.soinside.com 2019 - 2024. All rights reserved.