c# - 发送带有 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
我一直在使用的类。但是我不确定两件事:
- 如何连接到服务器并发送电子邮件。我尝试
SmtpClient
像以前一样使用该课程,但我无法通过MailItem
. - 我不确定我创建提醒的代码是否正确。我无法发送消息,因此我也无法查看提醒是否正确显示在 Outlook 中。如果有人有使用提醒的经验,也将不胜感激对我如何创建提醒的评论。
这是我用来创建电子邮件和提醒的代码:
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# - 没有从“TKey”到“System.IEquatable”的装箱转换或类型参数转换
- php - 在多维数组中搜索包含特定值的键并删除不包含特定值的键
- mysql - 移动订单在未结订单 Wpdatatables 下发货
- android - 另一个“预期为 BEGIN_OBJECT 但为 BEGIN_ARRAY”的问题
- python - 给定一个时间戳列,我怎样才能间隔两个小时并显示在一个新列中?
- go-cd - GoCD 从多个分支拉取并部署到不同的环境
- go - Youtube-dl 直接下载到客户端浏览器
- neural-network - 迷你批处理神经网络
- javascript - 图片无法在 IE11 中加载
- sql - SQL Server 更改数据库内部的 dbo