gpt4 book ai didi

c# - 为什么 smtpclient 发送的电子邮件没有出现在已发送的项目中

转载 作者:可可西里 更新时间:2023-11-01 08:23:20 30 4
gpt4 key购买 nike

我实现了一个通过 .Net SmtpClient 发送电子邮件的服务器。邮件发送代码如下所示:

private static MailMessage SendMail(string to, string subject, string body)
{
MailMessage mailToSend = new MailMessage();
mailToSend.Body = body;
mailToSend.Subject = subject;
mailToSend.IsBodyHtml = true;
mailToSend.To.Add(to);
try
{
mailClient.Send(mailToSend);
}
catch (Exception ex)
{
//Log data...
}
mailToSend.Dispose();
}

并且在 Web.config 中我放置了邮件的凭据,类似这样:

<configuration>
<system.net>
<mailSettings>
<smtp from="autoemail@mailserver.org">
<network host="smtp.mailserver.org" password="pswdpswd" port="25" userName="autoemail" clientDomain="the-domain" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
</configuration>

电子邮件发送成功并且一切正常但是当我登录到交换服务器中的电子邮件用户时(例如通过 Outlook Web-App)我看不到通过 SmtpClient(通过代码)发送的邮件已发送项目文件夹。

如何在此文件夹中保留已发送邮件的副本?谢谢!

最佳答案

它们没有记录在已发送的项目中,因为它只是使用 SMTP 级别的用户帐户发送,并没有真正使用邮箱发送电子邮件。

您唯一的选择是不使用 SmtpClient 并使用 Exchange API发送邮件。

来自他们引用的样本:

ExchangeService service = new ExchangeService();  
service.AutodiscoverUrl("youremailaddress@yourdomain.com");

EmailMessage message = new EmailMessage(service);
message.Subject = subjectTextbox.Text;
message.Body = bodyTextbox.Text;
message.ToRecipients.Add(recipientTextbox.Text);
message.Save();

message.SendAndSaveCopy();

关于c# - 为什么 smtpclient 发送的电子邮件没有出现在已发送的项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24257524/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com