Exemple #1
0
        public EmailResponce Send(EmailMessage message)
        {
            EmailResponce responce = new EmailResponce();

            try
            {
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress(GetEmail(message.From));

                SmtpClient SmtpServer = new SmtpClient(Host, Port);

                //SmtpServer.EnableSsl = ((RequireSSL != null) ? RequireSSL : false);

                foreach (EmailClient email in message.to)
                {
                    if (email.Type == EmailClientType.TO)
                    {
                        mail.To.Add(GetEmail(email.Email));
                    }
                    else if (email.Type == EmailClientType.CC)
                    {
                        mail.CC.Add(GetEmail(email.Email));
                    }
                    else if (email.Type == EmailClientType.BCC)
                    {
                        mail.Bcc.Add(GetEmail(email.Email));
                    }
                }

                mail.Subject = message.Subject;

                mail.IsBodyHtml = message.IsHtml;
                mail.Body       = message.Message;

                if (Username != null)
                {
                    SmtpServer.Credentials = new System.Net.NetworkCredential(Username, Password);
                }
                else
                {
                    SmtpServer.UseDefaultCredentials = true;
                }

                SmtpServer.Send(mail);

                responce.Title      = "SUCCESS";
                responce.Message    = "Sent successfully";
                responce.WasSuccess = true;
            }
            catch (Exception eee)
            {
                responce.Title      = "ERROR";
                responce.Message    = eee.Message;
                responce.WasSuccess = false;
            }

            return(responce);
        }
Exemple #2
0
        public EmailResponce Send(EmailMessage message)
        {
            EmailResponce responce = new EmailResponce();

            try
            {
                MailMessage mail = new MailMessage();

                mail.From = new MailAddress(GetEmail(message.From));

                SmtpClient SmtpServer = new SmtpClient(Host, Port);

                //SmtpServer.EnableSsl = ((RequireSSL != null) ? RequireSSL : false);

                foreach (EmailClient email in message.to)
                {
                    if (email.Type == EmailClientType.TO)
                        mail.To.Add(GetEmail(email.Email));
                    else if (email.Type == EmailClientType.CC)
                        mail.CC.Add(GetEmail(email.Email));
                    else if (email.Type == EmailClientType.BCC)
                        mail.Bcc.Add(GetEmail(email.Email));
                }

                mail.Subject = message.Subject;

                mail.IsBodyHtml = message.IsHtml;
                mail.Body = message.Message;

                if (Username != null)
                    SmtpServer.Credentials = new System.Net.NetworkCredential(Username, Password);
                else
                    SmtpServer.UseDefaultCredentials = true;

                SmtpServer.Send(mail);

                responce.Title = "SUCCESS";
                responce.Message = "Sent successfully";
                responce.WasSuccess = true;
            }
            catch (Exception eee)
            {
                responce.Title = "ERROR";
                responce.Message = eee.Message;
                responce.WasSuccess = false;
            }

            return responce;
        }