首页 > 解决方案 > 发送带有 Outlook 提醒的电子邮件

问题描述

介绍

我目前有一个允许我发送电子邮件的 C# 方法(见下文)。电子邮件是通过 Microsoft Exchange 服务器发送的,电子邮件是使用 Outlook 客户端读取的。我想为此方法添加其他功能,以便在发送时间后 24 小时内包含后续提醒。根据我在网上阅读的内容,我需要使用Microsoft.Office.Interop.Outlook,但我一直无法弄清楚如何使用它。

当前方法

using System.Net.Mail;

public void SendEmail(string host, string un, string pw, string from, string to, string subject, string body)
{
     MailMessage email = new MailMessage(from, to);
     email.Subject = subject;
     email.Body = body;

     SmtpClient client = new SmtpClient();
     client.UseDefaultCredentials = false;
     client.EnableSsl = true;
     client.Credentials = new NetworkCredential(un, pw);
     client.Host = host;
     client.Send(email);
}

我试过的

我相信我需要使用Microsoft.Office.Interop.Outlook.MailItem类来创建电子邮件,而不是MailMessage我一直在使用的类。但是我不确定两件事:

这是我用来创建电子邮件和提醒的代码:

using Microsoft.Office.Interop.Outlook;
    
public void SendEmail(string host, string un, string pw, string from, string to, string subject, string body)
{
    MailItem email = new MailItem();
    email.ReminderTime = new DateTime();
    email.ReminderTime = DateTime.Now;
    email.ReminderTime.AddDays(1);
    email.ReminderSet = true;
    email.Subject = subject;
    email.Body = body;
}

标签: c#emailoutlook

解决方案


推荐阅读