Created
October 16, 2016 08:52
-
-
Save constructor-igor/4b3f70cd53cc8e56de89baed38e1a1e7 to your computer and use it in GitHub Desktop.
Sending email (Outlook) from cake script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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