打开Outlook发邮件界面,发邮件
private void SendMailAttach(string to,string bcc,string subject,string body,bool html,string FileNameforEMail)
{
Outlook._Application oApp = new Outlook.Application();
Outlook.NameSpace oNameSpace= oApp.GetNamespace("MAPI");
try
{
oNameSpace.Logon(Missing.Value, Missing.Value,true,true);
Outlook.MAPIFolder oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Outlook.ApplicationClass a = new Outlook.ApplicationClass();
Outlook.MailItemClass tt;
tt=(Outlook.MailItemClass)a.CreateItem(OlItemType.olMailItem);
tt.To=to;
tt.CC = bcc;
tt.Subject=subject;
if(html)
{
tt.HTMLBody=body;
}
else
{
tt.Body=body;
}
tt.SaveSentMessageFolder=oOutboxFolder;
tt.Attachments.Add(FileNameforEMail,Missing.Value,Missing.Value,Missing.Value);
tt.Display(null);
}
finally
{
oNameSpace.Logoff();
}
}
{
Outlook._Application oApp = new Outlook.Application();
Outlook.NameSpace oNameSpace= oApp.GetNamespace("MAPI");
try
{
oNameSpace.Logon(Missing.Value, Missing.Value,true,true);
Outlook.MAPIFolder oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail);
Outlook.ApplicationClass a = new Outlook.ApplicationClass();
Outlook.MailItemClass tt;
tt=(Outlook.MailItemClass)a.CreateItem(OlItemType.olMailItem);
tt.To=to;
tt.CC = bcc;
tt.Subject=subject;
if(html)
{
tt.HTMLBody=body;
}
else
{
tt.Body=body;
}
tt.SaveSentMessageFolder=oOutboxFolder;
tt.Attachments.Add(FileNameforEMail,Missing.Value,Missing.Value,Missing.Value);
tt.Display(null);
}
finally
{
oNameSpace.Logoff();
}
}