Exemplo n.º 1
0
        public MailReturnValue ValidateSendMail(string fromMail, string mailSubject, string mailBody, string toMail)
        {
            bool IsGoodFromMail = ValidationEmail.GetInstance.ValidateEmail(fromMail);

            if (!IsGoodFromMail)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailFrom);
                return(result);
            }
            bool isGoodToMail = ValidationEmail.GetInstance.ValidateEmail(toMail);

            if (!isGoodToMail)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailTo);
                return(result);
            }
            if (string.IsNullOrEmpty(mailBody) || string.IsNullOrWhiteSpace(mailBody))
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailBody);
                return(result);
            }
            if (string.IsNullOrEmpty(mailSubject) || string.IsNullOrWhiteSpace(mailSubject))
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailSubject);
                return(result);
            }
            result = result.SetMailReturnValue(true, string.Empty);
            return(result);
        }
Exemplo n.º 2
0
        public virtual async Task <MailReturnValue> SentMailAsync(object mailMessage)
        {
            try
            {
                if (mailMessage == null)
                {
                    result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailMessageNull);
                }
                result = result.SetMailReturnValue(true, string.Empty);
                SmtpClient smtpClient = new SmtpClient(EmailProperties.GetInstance.SMTPMailHost, EmailProperties.GetInstance.SMTPMailPort);
                smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
                await smtpClient.SendMailAsync((MailMessage)mailMessage);

                result = result.SetMailReturnValue(true, string.Empty);
                // client.Credentials = new NetworkCredential(
                //"*****@*****.**", "humber123");
            }
            catch (ArgumentNullException ex)
            {
                result = result.SetMailReturnValue(false, "ArgumentNullException : " + ex.Message);
                return(result);
            }
            catch (ObjectDisposedException ex)
            {
                result = result.SetMailReturnValue(false, "ObjectDisposedException_" + ex.Message);
                return(result);
            }
            catch (SmtpFailedRecipientsException ex)
            {
                result = result.SetMailReturnValue(false, "SmtpFailedRecipientsException  : " + ex.Message);
                return(result);
            }
            catch (SmtpFailedRecipientException ex)
            {
                result = result.SetMailReturnValue(false, "SmtpFailedRecipientException : " + ex.Message);
                return(result);
            }
            catch (SmtpException ex)
            {
                result = result.SetMailReturnValue(false, "SmtpException : " + ex.Message);
                return(result);
            }
            catch (InvalidOperationException ex)
            {
                result = result.SetMailReturnValue(false, "InvalidOperationException : " + ex.Message);
                return(result);
            }
            catch (Exception ex)
            {
                result = result.SetMailReturnValue(false, "Exception : " + ex.Message);
                return(result);
            }
            return(result);
        }
Exemplo n.º 3
0
        public virtual MailReturnValue SendEmailThread(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, EmailToList toMails)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMails);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            MailMessage mailMessage = (MailMessage)CreateSMTPMessage.GetInstance.CreateMessage(fromMail, mailSubject, mailBody, isBodyHTML, toMails);

            ClientSMTP.GetInstance.SentMailThread(mailMessage);
            return(result);
        }
Exemplo n.º 4
0
 public virtual MailReturnValue SendEmail(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, EmailToList toMails)
 {
     result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMails);
     if (!result.IsSuccessMail)
     {
         return(result);
     }
     Microsoft.Exchange.WebServices.Data.EmailMessage mailMessage = (Microsoft.Exchange.WebServices.Data.EmailMessage)
                                                                    CreateOutlookMessage.GetInstance.CreateMessage(fromMail, mailSubject, mailBody, isBodyHTML, toMails);
     result = ClientOutlook.GetInstance.SentMail(mailMessage);
     return(result);
 }
Exemplo n.º 5
0
        public async virtual Task <MailReturnValue> SendEmailAsync(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, string toMail, string toCC, string toBCC)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMail, toCC, toBCC);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            Microsoft.Exchange.WebServices.Data.EmailMessage mailMessage = (Microsoft.Exchange.WebServices.Data.EmailMessage)
                                                                           CreateOutlookMessage.GetInstance.CreateMessage(fromMail, mailSubject, mailBody, isBodyHTML, toMail, toCC, toBCC);
            result = await ClientOutlook.GetInstance.SentMailAsync(mailMessage);

            return(result);
        }
Exemplo n.º 6
0
        public virtual async Task <MailReturnValue> SendEmailAsync(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, string toMail, string toCC, string toBCC)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMail, toCC, toBCC);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            MailMessage mailMessage = (MailMessage)CreateSMTPMessage.GetInstance.CreateMessage(fromMail, mailSubject, mailBody, isBodyHTML, toMail, toCC, toBCC);

            result = await ClientSMTP.GetInstance.SentMailAsync(mailMessage);

            return(result);
        }
Exemplo n.º 7
0
 public MailReturnValue ValidateSendMail(string fromMail, string mailSubject, string mailBody, string toMail, string toCC, string toBCC)
 {
     result = this.ValidateSendMail(fromMail, mailSubject, mailBody, toMail, toCC);
     if (result.IsSuccessMail)
     {
         bool IsGoodBCCMail = ValidationEmail.GetInstance.ValidateEmail(toBCC);
         if (!IsGoodBCCMail)
         {
             result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailBCC);
             return(result);
         }
     }
     return(result);
 }
Exemplo n.º 8
0
        public MailReturnValue SendEmailThread(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, string toMail, string toCC, List <EmailAttachment> emailAttachments)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toCC);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            result = ValidationAtttachment.GetInstance.ValidateAttachment(emailAttachments);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            MailMessage mailMessage = (MailMessage)CreateSMTPMessageAttachment.GetInstance.CreateMessageWithAttachment(fromMail, mailSubject, mailBody, isBodyHTML, toCC, emailAttachments);

            ClientSMTP.GetInstance.SentMailThread(mailMessage);
            return(result);
        }
Exemplo n.º 9
0
        public virtual MailReturnValue SendEmail(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, EmailToList toMails, List <EmailAttachment> emailAttachments, int sizeLimit)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMails);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            result = ValidationAtttachment.GetInstance.ValidateAttachment(emailAttachments, sizeLimit);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            MailMessage mailMessage = (MailMessage)CreateSMTPMessageAttachment.GetInstance.CreateMessageWithAttachment(fromMail, mailSubject, mailBody, isBodyHTML, toMails, emailAttachments);

            result = ClientSMTP.GetInstance.SentMail(mailMessage);
            return(result);
        }
Exemplo n.º 10
0
 public virtual MailReturnValue SendEmail(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, string toMail, string toCC, List <EmailAttachment> emailAttachments)
 {
     result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMail, toCC);
     if (!result.IsSuccessMail)
     {
         return(result);
     }
     result = ValidationAtttachment.GetInstance.ValidateAttachment(emailAttachments);
     if (!result.IsSuccessMail)
     {
         return(result);
     }
     Microsoft.Exchange.WebServices.Data.EmailMessage mailMessage = (Microsoft.Exchange.WebServices.Data.EmailMessage)
                                                                    CreateOutlookMessageAttachment.GetInstance.CreateMessageWithAttachment(fromMail, mailSubject, mailBody, isBodyHTML, toMail, toCC, emailAttachments);
     result = ClientOutlook.GetInstance.SentMail(mailMessage);
     return(result);
 }
Exemplo n.º 11
0
 public virtual MailReturnValue SentMail(object mailMessage)
 {
     try
     {
         if (mailMessage == null)
         {
             result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailMessageNull);
         }
         result = result.SetMailReturnValue(true, string.Empty);
         SmtpClient smtpClient = new SmtpClient(EmailProperties.GetInstance.SMTPMailHost, EmailProperties.GetInstance.SMTPMailPort);
         smtpClient.Credentials = CredentialCache.DefaultNetworkCredentials;
         smtpClient.Send((MailMessage)mailMessage);
         result = result.SetMailReturnValue(true, string.Empty);
     }
     catch (ArgumentNullException ex) {
         result = result.SetMailReturnValue(false, "ArgumentNullException : " + ex.Message);
         return(result);
     }
     catch (ObjectDisposedException ex) {
         result = result.SetMailReturnValue(false, "ObjectDisposedException_" + ex.Message);
         return(result);
     }
     catch (SmtpFailedRecipientsException ex) {
         result = result.SetMailReturnValue(false, "SmtpFailedRecipientsException  : " + ex.Message);
         return(result);
     }
     catch (SmtpFailedRecipientException ex) {
         result = result.SetMailReturnValue(false, "SmtpFailedRecipientException : " + ex.Message);
         return(result);
     }
     catch (SmtpException ex) {
         result = result.SetMailReturnValue(false, "SmtpException : " + ex.Message);
         return(result);
     }
     catch (InvalidOperationException ex) {
         result = result.SetMailReturnValue(false, "InvalidOperationException : " + ex.Message);
         return(result);
     }
     catch (Exception ex)
     {
         result = result.SetMailReturnValue(false, "Exception : " + ex.Message);
         return(result);
     }
     return(result);
 }
Exemplo n.º 12
0
        public async virtual Task <MailReturnValue> SendEmailAsync(string fromMail, string mailSubject, string mailBody, bool isBodyHTML, EmailToList toMails, List <EmailAttachment> emailAttachments, int sizeLimit)
        {
            result = ValidationSendMail.GetInstance.ValidateSendMail(fromMail, mailSubject, mailBody, toMails);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            result = ValidationAtttachment.GetInstance.ValidateAttachment(emailAttachments, sizeLimit);
            if (!result.IsSuccessMail)
            {
                return(result);
            }
            Microsoft.Exchange.WebServices.Data.EmailMessage mailMessage = (Microsoft.Exchange.WebServices.Data.EmailMessage)
                                                                           CreateOutlookMessageAttachment.GetInstance.CreateMessageWithAttachment(fromMail, mailSubject, mailBody, isBodyHTML, toMails, emailAttachments);
            result = await ClientOutlook.GetInstance.SentMailAsync(mailMessage);

            return(result);
        }
Exemplo n.º 13
0
        public MailReturnValue ValidateAttachment(List <EmailAttachment> emailAttachments, int sizeLimit)
        {
            int emailLimit = sizeLimit;
            int totLimit   = 0;

            foreach (var item in emailAttachments)
            {
                totLimit += item.FileAttachment.Length;
            }
            if (totLimit < emailLimit)
            {
                result = result.SetMailReturnValue(true, string.Empty);
            }
            else
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongAttachment + " Max Size : " + sizeLimit.ToString());
            }
            return(result);
        }
Exemplo n.º 14
0
        public MailReturnValue ValidateSendMail(string fromMail, string mailSubject, string mailBody, EmailToList toMails)
        {
            if (toMails == null)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongEmailToListNull); return(result);
            }
            if (toMails.ListEmailTo == null & toMails.ListEmailCc == null & toMails.ListEmailBcc == null)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongEmailToListNull);
            }
            if (toMails.ListEmailTo.Count + toMails.ListEmailCc.Count + toMails.ListEmailBcc.Count == 0)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongEmailToListNull);
            }
            bool isGoodToMail = ValidationEmail.GetInstance.ValidateEmail(toMails.ListEmailTo.ToArray());

            if (!isGoodToMail)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailTo);
                return(result);
            }
            bool isGoodCCMail = ValidationEmail.GetInstance.ValidateEmail(toMails.ListEmailCc.ToArray());

            if (!isGoodCCMail)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailCC);
                return(result);
            }
            bool isGoodBCCMail = ValidationEmail.GetInstance.ValidateEmail(toMails.ListEmailBcc.ToArray());

            if (!isGoodBCCMail)
            {
                result = result.SetMailReturnValue(false, EmailProperties.GetInstance.WrongMailBCC);
                return(result);
            }
            result = result.SetMailReturnValue(true, string.Empty);
            return(result);
        }