Example #1
0
        public ActionResultExtended Send(string fromAddress, string to, string cc, string messageSubject, string messageBody, string[] attachments, bool isBodyHtml)
        {
            string toAddress = ParseEmailAddress(to);
            string ccAddress = ParseEmailAddress(cc);

            string[] toAddressArray;
            if (toAddress != string.Empty)
            {
                toAddressArray = toAddress.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                toAddressArray = new String[0];
            }

            string[] ccAddressArray;
            if (ccAddress != string.Empty)
            {
                ccAddressArray = ccAddress.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                ccAddressArray = new String[0];
            }

            ActionResultExtended result = Send(fromAddress, toAddressArray, messageSubject, messageBody, ccAddressArray, attachments, isBodyHtml);

            if (result.ReturnCode == ReturnCode.Success || result.ReturnCode == ReturnCode.SuccessWithErrors)
            {
                // Log this email
                //         NotificationLog[] notificationLogs = { new NotificationLog(toAddress, ccAddress, messageSubject, messageBody, (attachments!= null && attachments.Length > 0)) };

                //            NotificationLogManagement notificationLogManagement = new NotificationLogManagement();
                //           notificationLogManagement.AddNotificationLogs(notificationLogs);
            }

            return(result);
        }
Example #2
0
        public ActionResultExtended ValidateEmailAddress(string email)
        {
            ActionResultExtended actionResult = new ActionResultExtended();
            List <ReturnProblem> problems     = new List <ReturnProblem>();

            if (!string.IsNullOrWhiteSpace(email) && !EmailManagement.IsValidEmailAddress(email))
            {
                problems.Add(new ReturnProblem(Guid.Empty, "email", "_Email", "EmailManagement_InvalidEmailAddress"));
            }

            if (problems.Count > 0)
            {
                actionResult.ReturnCode    = ReturnCode.Fail;
                actionResult.ReturnMessage = "EmailManagement_EmailValidationFailed";
                actionResult.ReturnProblems.AddRange(problems);
            }
            else
            {
                actionResult.ReturnCode = ReturnCode.Success;
            }

            return(actionResult);
        }
Example #3
0
        public ActionResultExtended Send(string to, string cc, string messageSubject, string messageBody, byte[][] attachmentDatas, String[] attachmentFileNames, bool isBodyHtml)
        {
            if (attachmentDatas == null || attachmentFileNames == null || attachmentDatas.Length != attachmentFileNames.Length)
            {
                attachmentFileNames = new String[0];
            }

            String tempPath = Path.GetTempPath();

            for (int i = 0; i < attachmentFileNames.Length; i++)
            {
                try
                {
                    if (!attachmentFileNames[i].Contains("\\"))
                    {
                        attachmentFileNames[i] = Path.Combine(tempPath, attachmentFileNames[i]);
                    }
                    using (BinaryWriter bw = new BinaryWriter(new FileStream(attachmentFileNames[i], FileMode.Create)))
                    {
                        bw.Write(attachmentDatas[i]);
                    }
                }
                catch (IOException ex)
                {
                    //            m_Log.Error(String.Format("Error writing attachment to file {0}", attachmentFileNames[i]), ex);
                }
            }

            ActionResultExtended result = Send(AddressFrom, to, cc, messageSubject, messageBody, attachmentFileNames, isBodyHtml);

            for (int i = 0; i < attachmentFileNames.Length; i++)
            {
                File.Delete(attachmentFileNames[i]);
            }

            return(result);
        }