我在将文件附加到 Outlook 时遇到问题。
我有这段代码,我可以在其中附加一个文件,然后使用我的 Outlook 发送它(没有凭据,只需在 Windows 中使用我的个人资料凭据)
private void tsbOk_Click(object sender, EventArgs e)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
((Outlook.MailItem)email).Importance = Outlook.OlImportance.olImportanceHigh;
((Outlook.MailItem)email).To = "myemail@maydomain.com";
//((Outlook.MailItem)email).CC = "myemail@maydomain.com";
((Outlook.MailItem)email).Subject = lblUser.Text + " - " + lblDepartment.Text;
**((Outlook.MailItem)email).Attachments.Add(lblAdd.Text.ToString(), Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing); **
((Outlook.MailItem)email).Body = lblFail.Text + "\n" + "\n" + lblDescription.Text + "\n" + "\n" + lblComment.Text;
((Outlook.MailItem)email).Send();
{
MessageBox.Show("Su solicitud ha sido enviada." + "\n" + "Gracias por contactar ServiceDesk BA.");
Close();
}
}
我将此部分用于文件, lblAdd.text 是我获取文件路径的地方:
((Outlook.MailItem)email).Attachments.Add(lblAdd.Text.ToString(), Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
问题是当此路径为空时,我无法在没有附件的情况下发送电子邮件,因为我更改了这部分代码。我怎样才能为此添加“例外”???
非常感谢您的帮助。问候