コード例 #1
3
ファイル: Email.cs プロジェクト: Livingst0n/pocketjobcoach
        /// <summary>
        /// Sends an email via G-Mail with the provided email settings.
        /// </summary>
        /// <param name="fromEmailAddress"></param>
        /// <param name="toEmailAddress"></param>
        /// <param name="subject"></param>
        /// <param name="messageBody"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static void send(string fromEmailAddress, string fromName, string toEmailAddress, string subject, string messageBody, string password, string server, int port, int timeout)
        {
            CDO.Message smtp = new CDO.Message();
            CDO.Configuration smtpConfig = new CDO.Configuration();

            ADODB.Fields fieldCollection = smtpConfig.Fields;
            ADODB.Field serverField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            serverField.Value = server; 
            ADODB.Field usernameField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            usernameField.Value = fromEmailAddress;
            ADODB.Field passwordField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            passwordField.Value = password;
            ADODB.Field authField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            authField.Value = 1;
            ADODB.Field timeoutField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"];
            timeoutField.Value = timeout;
            ADODB.Field serverPortField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            serverPortField.Value = port;
            ADODB.Field sendUsingField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            sendUsingField.Value = 2;
            ADODB.Field useSSLField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            useSSLField.Value = 1;
            fieldCollection.Update();

            smtp.Configuration = smtpConfig;
            smtp.Subject = subject;
            smtp.From = fromEmailAddress;
            smtp.To = toEmailAddress;
            smtp.Sender = fromName;
            smtp.Organization = fromName;
            smtp.ReplyTo = fromEmailAddress;
            smtp.TextBody = messageBody;
            smtp.Send();
        }
コード例 #2
0
        /// <summary>
        /// Sends an email via G-Mail with the provided email settings.
        /// </summary>
        /// <param name="fromEmailAddress"></param>
        /// <param name="toEmailAddress"></param>
        /// <param name="subject"></param>
        /// <param name="messageBody"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static void send(string fromEmailAddress, string fromName, string toEmailAddress, string subject, string messageBody, string password, string server, int port, int timeout)
        {
            CDO.Message       smtp       = new CDO.Message();
            CDO.Configuration smtpConfig = new CDO.Configuration();

            ADODB.Fields fieldCollection = smtpConfig.Fields;
            ADODB.Field  serverField     = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserver"];
            serverField.Value = server;
            ADODB.Field usernameField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusername"];
            usernameField.Value = fromEmailAddress;
            ADODB.Field passwordField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
            passwordField.Value = password;
            ADODB.Field authField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
            authField.Value = 1;
            ADODB.Field timeoutField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"];
            timeoutField.Value = timeout;
            ADODB.Field serverPortField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
            serverPortField.Value = port;
            ADODB.Field sendUsingField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/sendusing"];
            sendUsingField.Value = 2;
            ADODB.Field useSSLField = fieldCollection["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
            useSSLField.Value = 1;
            fieldCollection.Update();

            smtp.Configuration = smtpConfig;
            smtp.Subject       = subject;
            smtp.From          = fromEmailAddress;
            smtp.To            = toEmailAddress;
            smtp.Sender        = fromName;
            smtp.Organization  = fromName;
            smtp.ReplyTo       = fromEmailAddress;
            smtp.TextBody      = messageBody;
            smtp.Send();
        }
コード例 #3
0
ファイル: IpTracker.cs プロジェクト: brian-spanton/IpTracker
        private void Notify(string subject, string textBody)
        {
            CDO.MessageClass  message = new CDO.MessageClass();
            CDO.Configuration config  = message.Configuration;

            config.Fields[CDO.CdoConfiguration.cdoAutoPromoteBodyParts].Value = true;
            config.Fields[CDO.CdoConfiguration.cdoURLGetLatestVersion].Value  = true;

            string server = m_Settings.GetValue("Email Server");

            if (server.Length > 0)
            {
                config.Fields[CDO.CdoConfiguration.cdoSendUsingMethod].Value = CDO.CdoSendUsing.cdoSendUsingPort;
                config.Fields[CDO.CdoConfiguration.cdoSMTPServer].Value      = server;
                config.Fields[CDO.CdoConfiguration.cdoSMTPServerPort].Value  = int.Parse(m_Settings.GetValue("Email Port"));

                string value = m_Settings.GetValue("Email Auth");
                CDO.CdoProtocolsAuthentication auth = (CDO.CdoProtocolsAuthentication)Enum.Parse(typeof(CDO.CdoProtocolsAuthentication), value);
                if (auth != CDO.CdoProtocolsAuthentication.cdoAnonymous)
                {
                    config.Fields[CDO.CdoConfiguration.cdoSMTPAuthenticate].Value = auth;
                    config.Fields[CDO.CdoConfiguration.cdoSendUserName].Value     = m_Settings.GetValue("Email Username");
                    config.Fields[CDO.CdoConfiguration.cdoSendPassword].Value     = m_Settings.GetValue("Email Password");
                    config.Fields[CDO.CdoConfiguration.cdoSMTPUseSSL].Value       = bool.Parse(m_Settings.GetValue("Email UseSSL"));
                }
            }
            else
            {
                config.Fields[CDO.CdoConfiguration.cdoSendUsingMethod].Value = CDO.CdoSendUsing.cdoSendUsingPickup;
            }

            config.Fields.Update();

            message.To      = m_Settings.GetValue("Email To");
            message.From    = m_Settings.GetValue("Email From");
            message.ReplyTo = m_Settings.GetValue("Email ReplyTo");
            message.Subject = subject;

            //string createUrl = m_Settings.GetValue("Email CreateUrl");
            //if (createUrl.Length > 0)
            //{
            //    message.CreateMHTMLBody(createUrl, CDO.CdoMHTMLFlags.cdoSuppressAll, null, null);
            //}
            message.TextBody = textBody;

            message.Send();

            Log.WriteLine("Notification sent to " + message.To);
        }
コード例 #4
0
ファイル: SaveWebPage.cs プロジェクト: NaturalWill/DMS
        public static void SaveWebPageToMHTFile2(string url, string filePath)
        {
            try
            {
                CDO.Message       msg = new CDO.Message();
                CDO.Configuration cfg = new CDO.Configuration();

                msg.Configuration = cfg;
                // 第一参数为url,第二参数为支持格式,第三参数为用户ID,第四参数为用户密码
                msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressAll, "", "");
                msg.GetStream().SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                msg = null;
                //MessageBox.Show("Save OK!!!");
            }
            catch //(Exception ex)
            {
                //MessageBox.Show("Error:" + ex.Message);
            }
        }
コード例 #5
0
ファイル: SaveWebPage.cs プロジェクト: NaturalWill/DMS
        public static void SaveWebPageToMHTFile2(string url, string filePath)
        {
            try
            {
                CDO.Message msg = new CDO.Message();
                CDO.Configuration cfg = new CDO.Configuration();

                msg.Configuration = cfg;
                // 第一参数为url,第二参数为支持格式,第三参数为用户ID,第四参数为用户密码
                msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressAll, "", "");
                msg.GetStream().SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                msg = null;
                //MessageBox.Show("Save OK!!!");
            }
            catch //(Exception ex)
            {
                //MessageBox.Show("Error:" + ex.Message);
            }
        }