using Microsoft.Office.Interop.Outlook; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Mail; using System.Text; using System.Threading.Tasks; using Outlook = Microsoft.Office.Interop.Outlook; namespace Tango.UnitTesting { [TestClass] [TestCategory("Outlook")] public class Outlook_TST { [TestMethod] public void Send_Email_With_Logs_Using_Outlook() { Application app = new Application(); MailItem email = (MailItem)app.CreateItem(OlItemType.olMailItem); email.Subject = "Machine Studio Test"; email.To = "roy@twine-s.com"; email.Body = "Some body"; email.Attachments.Add( "D:\\C#.txt", OlAttachmentType.olByValue, 1, "CSharp Code"); email.Importance = OlImportance.olImportanceNormal; email.Send(); } [TestMethod] public void Send_Email_With_Logs_With_Outlook_SMTP() { String sender = "roy@twine-s.com"; String recipient = "roy@twine-s.com"; SmtpClient client = new SmtpClient("smtp-mail.outlook.com"); client.Port = 587; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(sender, "Maya2018"); client.EnableSsl = true; client.Credentials = credentials; try { var mail = new MailMessage(sender.Trim(), recipient.Trim()); mail.Attachments.Add(new System.Net.Mail.Attachment(new FileStream("D:\\C#.txt", FileMode.Open), "C# Code")); mail.Subject = "Test Email"; mail.Body = "This is a test."; client.Send(mail); } catch (System.Exception ex) { throw ex; } } } }