Search This Blog

Tuesday, October 18, 2011

Create a Mail Item, Attach a Report, and Send the Mail Item


// 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 ......

Featured Posts

Discover powerful tools for digital investigations, IP intelligence, threat hunting, exposed services, data breach research and satellite imagery.

14 Powerful OSINT Tools for Cybersecurity | BytesXplorer </> Bytes Xplorer TECHNOLOGY • ...