我制作了一个向学生发送邮件的程序。使用带有凭据的SMTP服务器发送电子邮件的Windows窗体程序(用C#编写);
var message = new MailMessage();
foreach (var m in arr999)
{
message.Bcc.Add(m);
}
message.Bcc.Add(textBox3.Text);
message.From = new MailAddress(textBox3.Text, textBox2.Text);
message.Subject = textBox4.Text;
var htmlstring = "<P STYLE=\"font-size: 10pt; font-family: verdana;\">";
htmlstring += textBox5.Text.Replace(Environment.NewLine, "<br />");
htmlstring += "<br /><br />" + textBox6.Text.Replace(Environment.NewLine, "<br />");
message.Body = htmlstring;
message.IsBodyHtml = true;
var client = new SmtpClient("***", 25);
if (gebruikersnaam != "noreply")
{
client.Credentials = new System.Net.NetworkCredential(gebruikersnaam, wachtwoord);
}
client.Send(message);
MessageBox.Show("De E-mail is verstuurd!", "Voltooid!", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("De E-mail kan niet worden verstuurd.\n\nReden:\n" + ex.Message + "", "Fout", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
wachtlabel.Visible = false;
}
邮件服务器是Microsoft Exchange服务器。但是,如何将带有此程序的发送项目放入Outlook,Outlook Web App等的“发送邮件”文件夹中?
任何帮助将不胜感激。
答案 0 :(得分:0)
Outlook对象模型不允许您在已发送状态下创建新邮件并设置SentOn属性。您可以使用Redemption。以下几行(VB):
set Session = CreateObject("Redemption.RDOSession")
Session.Logon
set Folder = Session.GetDefaultFolder(olFolderSentMail)
set Msg = Folder.Items.Add
Msg.Sent = true 'must be done before calling Save!
set Recip = Msg.Recipients.Add("user@domain.demo")
Recip.Resolve
Msg.Subject = "test"
Msg.Body = "test body"
Msg.SentOn = Now
Msg.Save
C#版本(您需要下载并安装Redemption并将其添加到您的项目参考中):
RDOSesssion Session = new RDOSession();
Session.Logon();
RDOFolder Folder = Session.GetDefaultFolder(rdoDefaultFolders.olFolderSentMail);
RDOMail Msg = Folder.Items.Add("IPM.Note");
Msg.Sent = true; //must be done before calling Save!
RDORecipient Recip = Msg.Recipients.Add("user@domain.demo");
Recip.Resolve();
Msg.Subject = "test";
Msg.Body = "test body";
Msg.SentOn = Now;
Msg.Save();