Exemplo n.º 1
0
        public Boolean SendMessage(MessageModel msg)
        {
            bool result = false;

            String email = msg.to;
            email = email.Trim();

            var smtp = new SmtpClient
            {
                Host = email_host,
                Port = email_port,
                EnableSsl = email_use_ssl,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential(email_username, email_password)
            };

            try
            {
                using (var message = new MailMessage(msg.from, msg.to)
                {
                    IsBodyHtml = true,
                    Subject = msg.subject,
                    Body = msg.body
                })
                {
                    if( msg.cc.Length > 0)
                        foreach (String cc in msg.cc.Split(','))
                            message.CC.Add(new MailAddress(cc));

                    if( msg.bcc.Length > 0)
                        foreach (String bcc in msg.bcc.Split(','))
                            message.Bcc.Add(new MailAddress(bcc));

                    smtp.Send(message);
                    result = true;
                }

            }
            catch (SmtpException smtp_error)
            {
                throw smtp_error;
            }
            catch (ArgumentNullException argument_null_error)
            {
                throw argument_null_error;
            }

            return result;
        }
Exemplo n.º 2
0
        public Boolean SendMessage(String to, String cc, String bcc, String from,
            String subject, String body)
        {
            var message = new MessageModel()
            {
                to = to,
                cc = cc,
                bcc = bcc,
                from = from,
                subject = subject,
                body = body,
                status = String.Empty
            };

            return SendMessage(message);
        }