Ejemplo n.º 1
0
        public void SmtpTest()
        {

            using (SmtpClient smtpClient = new SmtpClient("smtp.163.com"))
            {

                smtpClient.Connect();

                smtpClient.UserName = "******";
                smtpClient.Password = "******";

                smtpClient.Authenticate("*****@*****.**", "lsong940");

                MailAddress from = new MailAddress("Lsong", "*****@*****.**");
                MailAddress to = new MailAddress("*****@*****.**");
                MailAddress cc = new MailAddress("Test<*****@*****.**>");

                MailMessage mailMessage = new MailMessage(from, to);
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");

                mailMessage.AddRecipient(cc, AddressType.Cc);
                mailMessage.AddRecipient("*****@*****.**", AddressType.Bcc);

                mailMessage.Charset = "UTF-8";
                mailMessage.Priority = MailPriority.High;
                mailMessage.Notification = true;

                mailMessage.AddCustomHeader("X-CustomHeader", "Value");
                mailMessage.AddCustomHeader("X-CompanyName", "Value");

                //string testCid = mailMessage.AddImage("C:\\test.bmp");

                //mailMessage.AddAttachment("C:\\test.zip");

                mailMessage.Subject = "This's a test Mail.";
                mailMessage.Body = "hello everybody .";
                mailMessage.HtmlBody =
                    string.Format("<html><body>hello everybody .<br /><img src='cid:{0}' /></body></html>", "");

                smtpClient.SendMail(mailMessage);
            }
        }
Ejemplo n.º 2
0
        public void SmtpTest()
        {
            using (SmtpClient smtpClient = new SmtpClient("smtp.163.com"))
            {
                smtpClient.Connect();

                smtpClient.UserName = "******";
                smtpClient.Password = "******";

                smtpClient.Authenticate("*****@*****.**", "lsong940");

                MailAddress from = new MailAddress("Lsong", "*****@*****.**");
                MailAddress to   = new MailAddress("*****@*****.**");
                MailAddress cc   = new MailAddress("Test<*****@*****.**>");

                MailMessage mailMessage = new MailMessage(from, to);
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");
                mailMessage.To.Add("*****@*****.**");

                mailMessage.AddRecipient(cc, AddressType.Cc);
                mailMessage.AddRecipient("*****@*****.**", AddressType.Bcc);

                mailMessage.Charset      = "UTF-8";
                mailMessage.Priority     = MailPriority.High;
                mailMessage.Notification = true;

                mailMessage.AddCustomHeader("X-CustomHeader", "Value");
                mailMessage.AddCustomHeader("X-CompanyName", "Value");

                //string testCid = mailMessage.AddImage("C:\\test.bmp");

                //mailMessage.AddAttachment("C:\\test.zip");

                mailMessage.Subject  = "This's a test Mail.";
                mailMessage.Body     = "hello everybody .";
                mailMessage.HtmlBody =
                    string.Format("<html><body>hello everybody .<br /><img src='cid:{0}' /></body></html>", "");

                smtpClient.SendMail(mailMessage);
            }
        }
Ejemplo n.º 3
0
        /// <summary>Sends a mail message using supplied MailMessage</summary>
        /// <param name="msg">MailMessage instance</param>
        /// <example>
        /// <code>
        ///		MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**");
        ///		msg.Subject = "Hi";
        ///		msg.Body = "Hello Joe Smith."
        /// 	Smtp smtp = new Smtp("mail.OpenSmtp.com", 25);
        ///		smtp.SendMail(msg);
        /// </code>
        /// </example>
        public void SendMail(MailMessage msg)
        {
            WriteToStream(string.Format("MAIL FROM: <{0}>\r\n", msg.From.Address));
            CheckForError(ReadFromStream(), ReplyConstants.OK);

            SendRecipientList(msg.To);
            SendRecipientList(msg.CC);
            SendRecipientList(msg.BCC);

            WriteToStream("DATA\r\n");
            CheckForError(ReadFromStream(), ReplyConstants.START_INPUT);


            OnStartedMessageTransfer(EventArgs.Empty);
            WriteToStream(string.Format("{0}\r\n.\r\n", msg));
            CheckForError(ReadFromStream(), ReplyConstants.OK);
            OnEndedMessageTransfer(EventArgs.Empty);

            WriteToStream( "QUIT\r\n");
            CheckForError(ReadFromStream(), ReplyConstants.QUIT);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// CheckMailMessage
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        protected bool CheckMailMessage(MailMessage message)
        {
            const string returnMessage = "Mail Message is missing ";

            if (message.To == null || message.To.Count <= 0)
            {
                throw new SmtpException(string.Format("{0}'To:' field", returnMessage));
            }
            return true;
        }
Ejemplo n.º 5
0
        /// <summary>Sends a mail message using supplied MailMessage properties as string params</summary>
        /// <param name="from">RFC 822 formatted email sender address</param>
        /// <param name="to">RFC 822 formatted email recipient address</param>
        /// <param name="subject">Subject of the email message</param>
        /// <param name="body">Text body of the email message</param>
        /// <example>
        /// <code>
        /// 	Smtp smtp = new Smtp("mail.OpenSmtp.com", 25);
        ///		smtp.SendMail("*****@*****.**", "*****@*****.**", "Hi", "Hello Joe Smith");
        /// </code>
        /// </example>
        public void SendMail(string from, string to, string subject, string body)
        {
            MailMessage msg = new MailMessage(from, to);
            msg.Subject = subject;
            msg.Body = body;

            SendMail(msg);
        }