예제 #1
0
        /// <summary>
        /// sending email message to MSMQ
        /// </summary>
        /// <param name="QueuePath">Queue path</param>
        /// <param name="message">Email Message</param>
        public void QueueMessage(string QueuePath, EmailEntity message)
        {
            Message msg = new Message();
            msg.Body = message;
            msg.Recoverable = true;
            msg.Formatter = new BinaryMessageFormatter();
            //msg.Formatter = new XmlMessageFormatter();

            if (!MessageQueue.Exists(QueuePath))
            {
                using (MessageQueue queue = MessageQueue.Create(QueuePath))
                {
                    queue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl, AccessControlEntryType.Set);
                    queue.Send(msg);
                }
            }
            else
            {
                using (MessageQueue queue = new MessageQueue(QueuePath))
                {
                    queue.Formatter = new BinaryMessageFormatter();
                    queue.Send(msg);
                }
            }
        }      
예제 #2
0
        /// <summary>
        /// sending email
        /// </summary>
        /// <param name="message">email message</param>
        public void SendMessage(EmailEntity message)
        {
            try
            {
                SMTPEntity smtp = message.SMTP;
                using (SmtpClient server = new SmtpClient(smtp.SMTP, smtp.Port))
                {
                    server.Credentials = new System.Net.NetworkCredential(smtp.UserName, smtp.Password);
                    server.DeliveryMethod = SmtpDeliveryMethod.Network;
                    server.EnableSsl = smtp.EnableSSL;

                    MailAddress mailFrom = new MailAddress(message.From, message.FriendlyName, Encoding.UTF8);

                    MailMessage mail = new MailMessage();

                    mail.From = mailFrom;
                    mail.Sender = mailFrom;

                    if (!message.IsBccAll)
                    {
                        foreach (var item in message.EmailTo)
                        {
                            mail.To.Add(item);
                        }

                        foreach (var item in message.EmailCc)
                        {
                            mail.CC.Add(item);
                        }

                        foreach (var item in message.EmailBcc)
                        {
                            mail.Bcc.Add(item);
                        }
                    }
                    else
                    {
                        foreach (var item in message.EmailTo)
                        {
                            mail.Bcc.Add(item);
                        }

                        foreach (var item in message.EmailCc)
                        {
                            mail.Bcc.Add(item);
                        }

                        foreach (var item in message.EmailBcc)
                        {
                            mail.Bcc.Add(item);
                        }
                    }

                    foreach (var item in message.AttachementPaths)
                    {
                        Attachment attach = new Attachment(item);
                        mail.Attachments.Add(attach);
                    }

                    mail.Subject = message.Subject;
                    mail.SubjectEncoding = Encoding.UTF8;
                    mail.Body = message.Message;
                    mail.BodyEncoding = Encoding.UTF8;
                    mail.IsBodyHtml = true;
                    mail.Priority = MailPriority.Normal;

                    server.Send(mail);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
예제 #3
0
        private string Serializer(EmailEntity entity)
        {
            string strXml = string.Empty;
            using (MemoryStream ms = new MemoryStream())
            {
                
                XmlSerializer xs = new XmlSerializer(typeof(EmailEntity));
                xs.Serialize(ms, entity);
                strXml = Encoding.UTF8.GetString(ms.ToArray());                
            }

            return strXml;
        }
예제 #4
0
        private void btnSendEmail_Click(object sender, EventArgs e)
        {
            QueueService svc = new QueueService();
            foreach (var item in paths)
            {
                for (int i = 0; i < 10; i++)
                {
                    var message = new EmailEntity();
                    message.EmailTo.Add("*****@*****.**");
                    message.EmailCc.Add("*****@*****.**");
                    message.FriendlyName = "BcsWebReporter";
                    message.From = "*****@*****.**";
                    message.Message = "Hello, This is a test!";
                    message.IsBccAll = true;
                    message.SMTP = new SMTPEntity
                    {
                        EnableSSL = false,
                        Password = "******",
                        Port = 25,
                        SMTP = "smtp.1and1.com",
                        UserName = "******"
                    };
                    message.Subject = item + " Just a test " + i.ToString();

                    svc.QueueMessage(item, message);
                }
            }

            MessageBox.Show("Init finished!");
        }