// namespace (add microsoft.office.interop.outlook.dll
using Outlook = Microsoft.Office.Interop.Outlook;
//code
private void SendMailThroughOutlook()
{
Outlook.MailItem mail = Application.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "File sent programatically";
Outlook.AddressEntry currentUser =
Application.Session.CurrentUser.AddressEntry;
if (currentUser.Type == "EX")
{
Outlook.ExchangeUser manager =
currentUser.GetExchangeUser().GetExchangeUserManager();
// Add recipient using display name, alias, or smtp address
mail.Recipients.Add(manager.PrimarySmtpAddress);
mail.Recipients.ResolveAll();
mail.Attachments.Add(@"c:\file.xlsx",
Outlook.OlAttachmentType.olByValue, Type.Missing,
Type.Missing);
mail.Send();
}
}
No comments:
Post a Comment
Thank you for Commenting Will reply soon ......