Exemple #1
0
        public AResponse SendMail(Mail.MailHost host, Mail.MsgRecipients recipientType, string subject, string body)
        {
            AResponse response = new AResponse();

            try
            {
                String[] recipients = GetRecipients(recipientType);
                foreach (String rec in recipients)
                {
                    var resp = SendMail(host, rec, subject, body);
                    if (resp.ResponseStatus != Enums.ActionResponse.Success)
                    {
                        throw resp.Exception;
                    }
                }

                response.ResponseStatus = Enums.ActionResponse.Success;
                response.StatusMessage  = String.Format("MailHost:{0} - {1}", host.ToString(), Constants.Mail.SuccessSending);
            }
            catch (Exception ex)
            {
                response.StatusMessage  = String.Format("MailHost:{0} - {1}", host.ToString(), Constants.Mail.ErrorWhileSendingMail);
                response.ResponseStatus = Enums.ActionResponse.Unknown;
                response.Exception      = ex;
            }

            return(response);
        }
Exemple #2
0
        public AResponse SendMail(Mail.MailHost host, string toAddress, string subject, string body)
        {
            AResponse response = new AResponse();

            try
            {
                switch (host)
                {
                case Mail.MailHost.Gmail:
                    var message = new MailMessage(new MailAddress(Options.FromAddress, ""), new MailAddress(toAddress, ""));
                    message.Subject = subject;
                    message.Body    = body;

                    Client.Send(message);
                    break;

                default:
                    throw new Exception("Mail client Unknown!");
                    break;
                }

                response.ResponseStatus = Enums.ActionResponse.Success;
                response.StatusMessage  = String.Format("MailHost:{0} - {1}", host.ToString(), Constants.Mail.SuccessSending);
            }
            catch (Exception ex)
            {
                response.StatusMessage  = String.Format("MailHost:{0} - {1}", host.ToString(), Constants.Mail.ErrorWhileSendingMail);
                response.ResponseStatus = Enums.ActionResponse.Unknown;
                response.Exception      = ex;
            }

            return(response);
        }