Example #1
0
        public ReturnValue SentEmail(int orderId, int releaseID, EmailMessage email)
        {
            ReturnValue _result = new ReturnValue();

            App_Log_Mail _app_Log_Mail = new App_Log_Mail();

            try
            {
                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString(), 25);

                DotNetOpenMail.SmtpAuth.SmtpAuthToken SmtpAuthToken =
                    new DotNetOpenMail.SmtpAuth.SmtpAuthToken(System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"].ToString(),
                                                              System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"].ToString());
                server.SmtpAuthToken = SmtpAuthToken;

                email.Send(server);
            }
            catch (Exception ex)
            {
                _app_Log_Mail.Success = false;
                _app_Log_Mail.Notes   = ex.ToString();

                _result.Success    = false;
                _result.ErrMessage = _app_Log_Mail.Notes;

                return(_result);
            }


            #region Log App_Log_Mail

            _app_Log_Mail.IsTest    = Common.IsTest;
            _app_Log_Mail.CreatedOn = System.DateTime.Now;
            if (email.FromAddress != null)
            {
                _app_Log_Mail.AddressFrom = email.FromAddress.Email;
            }

            foreach (EmailAddress item in email.ToAddresses)
            {
                _app_Log_Mail.AddressTo = _app_Log_Mail.AddressTo + item.Email + ";";
            }

            _app_Log_Mail.Subject = email.Subject;


            if (email.TextPart != null)
            {
                _app_Log_Mail.Content = email.TextPart.Contents;
            }
            if (email.HtmlPart != null)
            {
                _app_Log_Mail.Content = email.HtmlPart.Contents;
            }
            _app_Log_Mail.OId       = orderId.ToString();
            _app_Log_Mail.ReleaseID = releaseID;
            _app_Log_Mail.Success   = true;;
            _app_Log_Mail.Notes     = "";
            _app_Log_Mail.Type      = "ShippingConfirm";
            _app_Log_Mail.Save();

            #endregion

            return(_result);
        }
Example #2
0
        public ReturnValue SentInvoiceEmail(int invoiceId)
        {
            ReturnValue _result = new ReturnValue();

            string MailContent = "";

            string _emailTo = "";

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            Model.TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();

            try
            {
                #region generate Email Content

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerByInvoiceId(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;


                _result = _tProgram_Email.getEmailTemplate("ShipInvoices");
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tProgram_Email = _result.Object as Model.TProgram_EmailTF;

                string _mailHtmlContent = System.Web.HttpUtility.HtmlDecode(System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml));


                MailContent = _mailHtmlContent.Replace("[CustomerName]", _tCustomer.FirstName);

                EmailMessage _mail = new EmailMessage();

                _mail.HtmlPart    = new HtmlAttachment(MailContent);
                _mail.FromAddress = new EmailAddress(_tProgram_Email.RespondTo);
                _mail.Subject     = _tProgram_Email.Subject;



                #endregion

                #region setup EmailMessage

                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _emailTo = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tCustomer.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            if (string.IsNullOrEmpty(_item) == false)
                            {
                                _mail.AddToAddress(new EmailAddress(_item));
                            }
                        }
                    }

                    _emailTo = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(_tProgram_Email.BccAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(_tProgram_Email.CCAddress) == false)
                {
                    string[] bcclist = _tProgram_Email.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(_tCustomer.InvoiceEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.InvoiceEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                #endregion

                #region attached pdf

                string pdffilename = "";


                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(invoiceId);
                if (_result.Success == false)
                {
                    return(_result);
                }

                pdffilename = "Invoice/TFInvoice_" + invoiceId.ToString() + ".pdf";



                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";

                _mail.AddMixedAttachment(fileAttachment);

                #endregion

                DotNetOpenMail.SmtpAuth.SmtpAuthToken token = new DotNetOpenMail.SmtpAuth.SmtpAuthToken(
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"],
                    System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"]);


                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"]);
                server.SmtpAuthToken = token;

                if (_mail.Send(server) == false)
                {
                    _result.Success = false;
                }
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            #region Log App_Log_Mail
            App_Log_Mail _app_Log_Mail = new App_Log_Mail();
            // _app_Log_Mail.ProgramId = this.Owner.DefaultProgram.ProgramId;
            _app_Log_Mail.IsTest      = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString());
            _app_Log_Mail.CreatedOn   = System.DateTime.Now;
            _app_Log_Mail.AddressFrom = _tProgram_Email.RespondTo;
            _app_Log_Mail.AddressTo   = _emailTo;
            _app_Log_Mail.AddressBcc  = _tProgram_Email.BccAddress;
            _app_Log_Mail.Subject     = _tProgram_Email.Subject;
            _app_Log_Mail.Content     = MailContent;

            _app_Log_Mail.OId     = invoiceId.ToString();
            _app_Log_Mail.Success = _result.Success;
            _app_Log_Mail.Notes   = _result.ErrMessage;
            _app_Log_Mail.Type    = "ShippingInvoice";
            _app_Log_Mail.Save();

            #endregion


            return(_result);
        }
Example #3
0
        public static ReturnValue SentEmail(TProgram_Email tProgram_Email, EmailFormat emailFormat, int oId, FileAttachment fileAttachment)
        {
            ReturnValue _result = new ReturnValue();

            bool IsTFTestMode = Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTFTestMode"].ToString());

            if (tProgram_Email.ContentStatusId != 1)
            {
                return(_result);
            }

            EmailMessage _mail = new EmailMessage();

            if (string.IsNullOrEmpty(tProgram_Email.RespondToName) == true)
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo);
            }
            else
            {
                _mail.FromAddress = new EmailAddress(tProgram_Email.RespondTo, tProgram_Email.RespondToName);
            }


            _mail.Subject = tProgram_Email.Subject;

            if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
            {
                _mail.HtmlPart = new HtmlAttachment(tProgram_Email.FullHtml);
            }
            if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
            {
                _mail.TextPart = new TextAttachment(tProgram_Email.FullText);
            }


            string _emailto = tProgram_Email.ToAddress;

            if (IsTFTestMode == true)
            {
                if (string.IsNullOrEmpty(Common.TestMailTo) == false)
                {
                    string[] ccList = Common.TestMailTo.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        _mail.AddToAddress(new EmailAddress(ccAddress));
                    }

                    _emailto = Common.TestMailTo;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(tProgram_Email.CCAddress) == false)
                {
                    string[] ccList = tProgram_Email.CCAddress.Split(';');
                    foreach (string ccAddress in ccList)
                    {
                        if (string.IsNullOrEmpty(ccAddress.Trim()) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(ccAddress));
                        }
                    }
                }


                if (string.IsNullOrEmpty(tProgram_Email.BccAddress) == false)
                {
                    string[] BccList = tProgram_Email.BccAddress.Split(';');
                    foreach (string bccAddress in BccList)
                    {
                        if (string.IsNullOrEmpty(bccAddress.Trim()) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(bccAddress));
                        }
                    }
                }
                if (string.IsNullOrEmpty(tProgram_Email.ToAddress) == false)
                {
                    string[] ToAddressList = tProgram_Email.ToAddress.Split(';');
                    foreach (string toAddress in ToAddressList)
                    {
                        if (string.IsNullOrEmpty(toAddress.Trim()) == false)
                        {
                            _mail.AddToAddress(new EmailAddress(toAddress));
                        }
                    }
                }
            }

            if (fileAttachment != null)
            {
                _mail.AddMixedAttachment(fileAttachment);
            }

            App_Log_Mail _mailLog = new App_Log_Mail();

            try
            {
                SmtpServer server = new SmtpServer(System.Configuration.ConfigurationSettings.AppSettings["SMTPServer"].ToString(), 25);

                DotNetOpenMail.SmtpAuth.SmtpAuthToken SmtpAuthToken =
                    new DotNetOpenMail.SmtpAuth.SmtpAuthToken(System.Configuration.ConfigurationSettings.AppSettings["SMTPUserName"].ToString(),
                                                              System.Configuration.ConfigurationSettings.AppSettings["SMTPPassword"].ToString());
                server.SmtpAuthToken = SmtpAuthToken;

                bool _success = _mail.Send(server);

                _mailLog.Success = _success;
                _mailLog.Notes   = "";
            }
            catch (Exception ex)
            {
                _mailLog.Success = false;
                _mailLog.Notes   = ex.ToString();
            }
            finally
            {
                _mailLog.AddressBcc  = "AddressBcc:" + (string.IsNullOrEmpty(tProgram_Email.BccAddress) ? "" : tProgram_Email.BccAddress) + " CCAddress:" + (string.IsNullOrEmpty(tProgram_Email.CCAddress) ? "" : tProgram_Email.CCAddress);
                _mailLog.AddressFrom = tProgram_Email.RespondTo;
                _mailLog.AddressTo   = _emailto;


                if (emailFormat == EmailFormat.Html || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullHtml;
                }
                if (emailFormat == EmailFormat.Text || emailFormat == EmailFormat.Both)
                {
                    _mailLog.Content = tProgram_Email.FullText;
                }

                _mailLog.CreatedOn = System.DateTime.Now;
                _mailLog.Subject   = tProgram_Email.Subject;
                _mailLog.Type      = tProgram_Email.EmailTypeId.ToString();
                _mailLog.OId       = oId.ToString();
                _mailLog.IsTest    = IsTFTestMode;
                _mailLog.Save();
            }

            _result.Success    = _mailLog.Success.Value;
            _result.ErrMessage = _mailLog.Notes;

            if (string.IsNullOrEmpty(_mailLog.AddressTo) == true)
            {
                _result.Success = true;
            }

            return(_result);
        }