Skip to content

Instantly share code, notes, and snippets.

@constructor-igor
Created October 16, 2016 08:52
Show Gist options
  • Save constructor-igor/4b3f70cd53cc8e56de89baed38e1a1e7 to your computer and use it in GitHub Desktop.
Save constructor-igor/4b3f70cd53cc8e56de89baed38e1a1e7 to your computer and use it in GitHub Desktop.
Sending email (Outlook) from cake script.
#addin "Microsoft.Office.Interop.Outlook"
using Outlook = Microsoft.Office.Interop.Outlook;
// ...
Task("Send-email")
.Does(()=>
{
//https://msdn.microsoft.com/en-us/library/office/bb644320.aspx
var reportFilePath = MakeAbsolute(File("testReport.html")).ToString();
Outlook.Application application = new Outlook.ApplicationClass();
Outlook.MailItem mail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.Subject = "subject";
Outlook.AddressEntry currentUser = application.Session.CurrentUser.AddressEntry;
mail.Recipients.Add(currentUser.Name);
mail.Attachments.Add(reportFilePath, Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
mail.Send();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment