Beispiel #1
0
 public static SystemSettings GetFileManagerSettings()
 {
     return(SystemController.GetSystemSettingsInternal(SystemSettings.FILEMANAGER_SETTINGS, false));
 }
Beispiel #2
0
        public static int SendMessage(string from, string to, string bcc, string subject, string body,
                                      MailPriority priority, bool isHtml, Attachment[] attachments)
        {
            // Command line argument must the the SMTP host.
            SmtpClient client = new SmtpClient();

            // load SMTP client settings
            SystemSettings settings = SystemController.GetSystemSettingsInternal(
                SystemSettings.SMTP_SETTINGS,
                true
                );

            client.Host = settings["SmtpServer"];
            client.Port = settings.GetInt("SmtpPort");
            if (!String.IsNullOrEmpty(settings["SmtpUsername"]))
            {
                client.Credentials = new NetworkCredential(
                    settings["SmtpUsername"],
                    settings["SmtpPassword"]
                    );
            }

            if (!String.IsNullOrEmpty(settings["SmtpEnableSsl"]))
            {
                client.EnableSsl = Utils.ParseBool(settings["SmtpEnableSsl"], false);
            }

            // create message
            MailMessage message = new MailMessage(from, to);

            message.Body            = body;
            message.BodyEncoding    = System.Text.Encoding.UTF8;
            message.IsBodyHtml      = isHtml;
            message.Subject         = subject;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            if (!String.IsNullOrEmpty(bcc))
            {
                message.Bcc.Add(bcc);
            }
            message.Priority = priority;

            if (attachments != null)
            {
                foreach (Attachment current in attachments)
                {
                    message.Attachments.Add(current);
                }
            }

            // send message
            try
            {
                client.Send(message);

                return(0);
            }
            catch (SmtpException ex)
            {
                switch (ex.StatusCode)
                {
                case SmtpStatusCode.BadCommandSequence: return(BusinessErrorCodes.SMTP_BAD_COMMAND_SEQUENCE);

                case SmtpStatusCode.CannotVerifyUserWillAttemptDelivery: return(BusinessErrorCodes.SMTP_CANNOT_VERIFY_USER_WILL_ATTEMPT_DELIVERY);

                case SmtpStatusCode.ClientNotPermitted: return(BusinessErrorCodes.SMTP_CLIENT_NOT_PERMITTED);

                case SmtpStatusCode.CommandNotImplemented: return(BusinessErrorCodes.SMTP_COMMAND_NOT_IMPLEMENTED);

                case SmtpStatusCode.CommandParameterNotImplemented: return(BusinessErrorCodes.SMTP_COMMAND_PARAMETER_NOT_IMPLEMENTED);

                case SmtpStatusCode.CommandUnrecognized: return(BusinessErrorCodes.SMTP_COMMAND_UNRECOGNIZED);

                case SmtpStatusCode.ExceededStorageAllocation: return(BusinessErrorCodes.SMTP_EXCEEDED_STORAGE_ALLOCATION);

                case SmtpStatusCode.GeneralFailure: return(BusinessErrorCodes.SMTP_GENERAL_FAILURE);

                case SmtpStatusCode.InsufficientStorage: return(BusinessErrorCodes.SMTP_INSUFFICIENT_STORAGE);

                case SmtpStatusCode.LocalErrorInProcessing: return(BusinessErrorCodes.SMTP_LOCAL_ERROR_IN_PROCESSING);

                case SmtpStatusCode.MailboxBusy: return(BusinessErrorCodes.SMTP_MAILBOX_BUSY);

                case SmtpStatusCode.MailboxNameNotAllowed: return(BusinessErrorCodes.SMTP_MAILBOX_NAME_NOTALLOWED);

                case SmtpStatusCode.MailboxUnavailable: return(BusinessErrorCodes.SMTP_MAILBOX_UNAVAILABLE);

                case SmtpStatusCode.MustIssueStartTlsFirst: return(BusinessErrorCodes.SMTP_MUST_ISSUE_START_TLS_FIRST);

                case SmtpStatusCode.ServiceClosingTransmissionChannel: return(BusinessErrorCodes.SMTP_SERVICE_CLOSING_TRANSMISSION_CHANNEL);

                case SmtpStatusCode.ServiceNotAvailable: return(BusinessErrorCodes.SMTP_SERVICE_NOT_AVAILABLE);

                case SmtpStatusCode.SyntaxError: return(BusinessErrorCodes.SMTP_SYNTAX_ERROR);

                case SmtpStatusCode.TransactionFailed: return(BusinessErrorCodes.SMTP_TRANSACTION_FAILED);

                case SmtpStatusCode.UserNotLocalTryAlternatePath: return(BusinessErrorCodes.SMTP_USER_NOT_LOCAL_TRY_ALTERNATE_PATH);

                case SmtpStatusCode.UserNotLocalWillForward: return(BusinessErrorCodes.SMTP_USER_NOT_LOCAL_WILL_FORWARD);

                default: return(BusinessErrorCodes.SMTP_UNKNOWN_ERROR);
                }
            }
            finally
            {
                // Clean up.
                message.Dispose();
            }
        }