Пример #1
0
        public void SendImplicitMail(List <MailAddress> recieverMailAddresses, MailPriority messagePriority, string messageSubject, string messageBody, List <string> attachmentAddress = null, List <MailAddress> ccMailAddresses = null, List <MailAddress> bccMailAddresses = null)
        {
            var msg = new MimeMailMessage
            {
                From       = new MailAddress(_senderEmailAddresss, _senderDisplayName),
                Subject    = messageSubject,
                Body       = messageBody,
                IsBodyHtml = _useHtml
            };

            recieverMailAddresses.ForEach(a => msg.To.Add(a));
            if (ccMailAddresses != null)
            {
                ccMailAddresses.ForEach(a => msg.To.Add(a));
            }
            if (bccMailAddresses != null)
            {
                bccMailAddresses.ForEach(a => msg.To.Add(a));
            }

            if (attachmentAddress != null)
            {
                attachmentAddress.ForEach(a => msg.Attachments.Add(new MimeAttachment(a)));
            }

            var mm = new MimeMailer(_host, _port, _userName, _passWord, _ssl, _authenticationType);

            mm.Send(msg, _onSendCallBack);
        }
Пример #2
0
        /// <summary>
        /// Generate ann email message
        /// </summary>
        /// <param name="sender">From field of mail</param>
        /// <param name="toAddresses">Recievers</param>
        /// <param name="ccAddresses">CC list</param>
        /// <param name="bccAddresses">BCC List</param>
        /// <param name="attachmentsList">List of files attached to this mail</param>
        /// <param name="subject">Subject of email</param>
        /// <param name="body">Message's busy</param>
        /// <returns>Generated message</returns>
        public AbstractMailMessage GenerateMail(IMailAddress sender, List <IMailAddress> toAddresses, List <IMailAddress> ccAddresses, List <IMailAddress> bccAddresses, List <string> attachmentsList,
                                                string subject, string body)
        {
            var msg = new MimeMailMessage
            {
                From    = (MailAddress)sender,
                Subject = subject,
                Body    = body
            };

            toAddresses.ForEach(a => msg.To.Add((MimeMailAddress)a));
            if (ccAddresses != null)
            {
                ccAddresses.ForEach(a => msg.To.Add((MimeMailAddress)a));
            }
            if (bccAddresses != null)
            {
                bccAddresses.ForEach(a => msg.To.Add((MimeMailAddress)(a)));
            }

            if (attachmentsList != null)
            {
                attachmentsList.ForEach(a => msg.Attachments.Add(new MimeAttachment(a)));
            }
            return(msg);
        }
Пример #3
0
        public void SendMail(List <MailAddress> recieverMailAddresses, MailPriority messagePriority, string messageSubject, string messageBody, List <string> attachmentAddress = null, SendCompletedEventHandler onSendCallBack = null, List <MailAddress> ccMailAddresses = null, List <MailAddress> bccMailAddresses = null)
        {
            var msg = new MimeMailMessage {
                From = new MimeMailAddress(_senderEmailAddresss, _senderDisplayName)
            };

            // Your mail address and display name.
            // This what will appear on the From field.
            // If you used another credentials to access
            // the SMTP server, the mail message would be
            // sent from the mail specified in the From
            // field on behalf of the real sender.

            // To addresses

            recieverMailAddresses.ForEach(a => msg.To.Add(a));
            if (ccMailAddresses != null)
            {
                ccMailAddresses.ForEach(a => msg.To.Add(a));
            }
            if (bccMailAddresses != null)
            {
                bccMailAddresses.ForEach(a => msg.To.Add(a));
            }

            // You can specify CC and BCC addresses also

            // Set to high priority
            msg.Priority = messagePriority;

            msg.Subject = messageSubject;

            // You can specify a plain text or HTML contents
            msg.Body = messageBody;
            // In order for the mail client to interpret message
            // body correctly, we mark the body as HTML
            // because we set the body to HTML contents.
            if (_useHtml)
            {
                msg.IsBodyHtml = true;
            }

            // Attaching some data

            if (attachmentAddress != null && attachmentAddress.Count > 0)
            {
                attachmentAddress.ForEach(a => msg.Attachments.Add(new MimeAttachment(a)));
            }


            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.BodyEncoding    = System.Text.Encoding.UTF8;
            msg.Priority        = MailPriority.High;

            SendMessage(msg, _onSendCallBack);
        }
Пример #4
0
        /// <summary>
        /// Send message to the server
        /// </summary>
        /// <param name="from">Sender address</param>
        /// <param name="recipient">receiver email address</param>
        /// <param name="subject">email subject</param>
        /// <param name="body">message content</param>
        public void Send(string from, string recipient, string subject, string body)
        {
            var allowUnicode = this.IsUnicodeSupported();
            var mailMessage  = new MimeMailMessage
            {
                From    = new MimeMailAddress(@from),
                Subject = subject,
                Body    = body
            };

            mailMessage.To.Add(new MimeMailAddress(recipient));
            Send(mailMessage);
        }