public void ToStringTest()
        {
            const string name           = "natalia";
            const string mail           = "*****@*****.**";
            string       expectedResult = $"{name} - {mail}";
            MailContact  mailContact    = new MailContact(name, mail);

            string actual = mailContact.ToString();

            Assert.AreEqual(actual, expectedResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sends a message
        /// </summary>
        /// <param name="Message">The message to send</param>
        /// <param name="From">The sender (From: header)</param>
        /// <param name="To">A list of recipients (To: header)</param>
        /// <param name="CC">A list of recipients (CC: header)</param>
        /// <param name="BCC">A list of recipients (in no header at all)</param>
        public void Send(MailMessage Message, MailContact From, MailContact[] To, MailContact[] CC = null, MailContact[] BCC = null)
        {
            // CC and BCC can be defined null
            if (CC == null)
            {
                CC = new MailContact[0];
            }
            if (BCC == null)
            {
                BCC = new MailContact[0];
            }
            // This array will be filled with all recipients
            string[] Recipients     = new string[To.Length + CC.Length + BCC.Length];
            int      RecipientIndex = 0;
            // Subject
            string MailHeaders = "Subject: " + Message.Subject + "\r\n";

            // From
            MailHeaders += "From: " + From.ToString() + "\r\n";
            // Reply-to
            MailHeaders += "Reply-to: <" + From.MailAddress + ">\r\n";
            // To
            MailHeaders += "To: ";
            for (int Counter = 0; Counter < To.Length; ++Counter)
            {
                MailHeaders += To[Counter].ToString() + ";";
                Recipients[RecipientIndex] = To[Counter].MailAddress;
                ++RecipientIndex;
            }
            MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            // BCC
            if (CC.Length != 0)
            {
                // CC
                MailHeaders += "CC: ";
                for (int Counter = 0; Counter < CC.Length; ++Counter)
                {
                    MailHeaders += CC[Counter].ToString() + ";";
                    Recipients[RecipientIndex] = CC[Counter].MailAddress;
                    ++RecipientIndex;
                }
                MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            }
            // BCC
            if (BCC.Length != 0)
            {
                for (int Counter = 0; Counter < BCC.Length; ++Counter)
                {
                    Recipients[RecipientIndex] = BCC[Counter].MailAddress;
                    ++RecipientIndex;
                }
            }
            // Date; below 2011, the date is probably not set and sending it will only give the message a higher spam score in spam filters
            if (DateTime.Now.Year > 2010)
            {
                MailHeaders += "Date: " + this._RFC2822_Date() + "\r\n";
            }
            // Message-ID
            MailHeaders += "Message-ID: <" + DateTime.Now.Ticks.ToString() + "@" + this._LocalHostname + ">\r\n";
            // Priority
            if (Message.Priority != 3)
            {
                MailHeaders += "X-Priority: " + Message.Priority.ToString() + "\r\n";
            }
            // Content Type
            MailHeaders += "Content-Type: " + Message.ContentType + "; charset=" + Message.CharacterSet + "\r\n";
            // Mailer
            MailHeaders += "X-Mailer: NETMFToolbox/0.1\r\n";

            // Actually sends the mail
            this._Send(From.MailAddress, Recipients, MailHeaders + "\r\n" + Message.Body);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a message
        /// </summary>
        /// <param name="Message">The message to send</param>
        /// <param name="From">The sender (From: header)</param>
        /// <param name="To">A list of recipients (To: header)</param>
        /// <param name="CC">A list of recipients (CC: header)</param>
        /// <param name="BCC">A list of recipients (in no header at all)</param>
        public void Send(MailMessage Message, MailContact From, MailContact[] To, MailContact[] CC = null, MailContact[] BCC = null)
        {
            // CC and BCC can be defined null
            if (CC == null) CC = new MailContact[0];
            if (BCC == null) BCC = new MailContact[0];
            // This array will be filled with all recipients
            string[] Recipients = new string[To.Length + CC.Length + BCC.Length];
            int RecipientIndex = 0;
            // Subject
            string MailHeaders = "Subject: " + Message.Subject + "\r\n";
            // From
            MailHeaders += "From: " + From.ToString() + "\r\n";
            // Reply-to
            MailHeaders += "Reply-to: <" + From.MailAddress + ">\r\n";
            // To
            MailHeaders += "To: ";
            for (int Counter = 0; Counter < To.Length; ++Counter)
            {
                MailHeaders += To[Counter].ToString() + ";";
                Recipients[RecipientIndex] = To[Counter].MailAddress;
                ++RecipientIndex;
            }
            MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            // BCC
            if (CC.Length != 0)
            {
                // CC
                MailHeaders += "CC: ";
                for (int Counter = 0; Counter < CC.Length; ++Counter)
                {
                    MailHeaders += CC[Counter].ToString() + ";";
                    Recipients[RecipientIndex] = CC[Counter].MailAddress;
                    ++RecipientIndex;
                }
                MailHeaders = MailHeaders.Substring(0, MailHeaders.Length - 1) + "\r\n";
            }
            // BCC
            if (BCC.Length != 0)
            {
                for (int Counter = 0; Counter < BCC.Length; ++Counter)
                {
                    Recipients[RecipientIndex] = BCC[Counter].MailAddress;
                    ++RecipientIndex;
                }
            }
            // Date; below 2011, the date is probably not set and sending it will only give the message a higher spam score in spam filters
            if (DateTime.Now.Year > 2010)
                MailHeaders += "Date: " + this._RFC2822_Date() + "\r\n";
            // Message-ID
            MailHeaders += "Message-ID: <" + DateTime.Now.Ticks.ToString() + "@" + this._LocalHostname + ">\r\n";
            // Priority
            if (Message.Priority != 3)
            {
                MailHeaders += "X-Priority: " + Message.Priority.ToString() + "\r\n";
            }
            // Content Type
            MailHeaders += "Content-Type: " + Message.ContentType + "; charset=" + Message.CharacterSet + "\r\n";
            // Mailer
            MailHeaders += "X-Mailer: NETMFToolbox/0.1\r\n";

            // Actually sends the mail
            this._Send(From.MailAddress, Recipients, MailHeaders + "\r\n" + Message.Body);
        }