aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.UnitTesting/Outlook_TST.cs
blob: 57a22dbd9bb81e40ccaa7ee0263ae424adededc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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;
            }
        }
    }
}