我正在尝试从HTML模板生成Outlook电子邮件,更改电子邮件中的某些值。
如果HTML模板中有图像,它们会起作用然后停止工作,而是显示“红叉”。他们通常在制作HTML模板后第二天停止工作。
我首先使用Outlook制作HTML模板,但实际上无法避免这种情况。
这是我的代码:
private void generateEmail(object sender, EventArgs e)
{
String firstDate = formatDate(dtFirstDate.Value);
String secondDate = formatDate(dtSecondDate.Value);
String dateOne = formatDate(dtDate1.Value);
String dateTwo = formatDate(dtDate2.Value);
String dateThree = formatDate(dtDate3.Value);
string strHTML = "";
string subjectPrefix = "";
try
{
strHTML = File.ReadAllText(templateLocation + "/PRF_Request.htm");
subjectPrefix = "PRF - ";
}
catch
{
MessageBox.Show("Template Not Found");
return;
}
/*
* Replace Placeholder Tags in the HTML with data.
*/
string email = strHTML
.Replace("�", " ")
//.Replace("##Name##", user)
.Replace("##application##", tAppName.Text + " (" + tVendor.Text + ") " + tVersion.Text)
.Replace("##FirstDate##", firstDate)
.Replace("##SecondDate##", secondDate)
.Replace("##date1##", dateOne)
.Replace("##date2##", dateTwo)
.Replace("##date3##", dateThree);
if (rbOutlook.Checked)
{
Microsoft.Office.Interop.Outlook.Application objOutlook = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem oMail = (Microsoft.Office.Interop.Outlook.MailItem)(objOutlook.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem));
//Microsoft.Office.Interop.Outlook.Attatchment colAttach = new Attachments;
// Assigns the default email attributes
oMail.To = "";
oMail.CC = "";
oMail.BCC = "";
oMail.Subject = subjectPrefix + tAppName.Text + " (" + tVendor.Text + ") " + tVersion.Text + " - " + tAppID.Text;
if (bImportance.Checked){
oMail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
}else{
oMail.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceNormal;
}
// Define the Mail Message Body.
oMail.HTMLBody = email;
oMail.Display();
}
else if (rbLotus.Checked)
{
MessageBox.Show("Generate Lotus Notes Email");
}
}