Пример #1
0
        private async void button1a_Click(object sender, RoutedEventArgs e)
        {
            Chilkat.MailMan mailman = new Chilkat.MailMan();

            if (!checkUnlocked())
            {
                return;
            }

            //  Set the SMTP server.
            mailman.SmtpHost     = "smtp.gmail.com";
            mailman.SmtpUsername = "******";
            mailman.SmtpPassword = "******";
            mailman.StartTLS     = true;
            mailman.SmtpPort     = 587;

            Chilkat.Email email = new Chilkat.Email();
            email.Subject = "This is a test";
            email.Body    = "This is a test";
            email.From    = "*****@*****.**";
            email.AddTo("Matt", "*****@*****.**");

            mailman.VerboseLogging = true;
            bool success = await mailman.SendEmailAsync(email);

            if (success != true)
            {
                textBox1.Text = mailman.LastErrorText;
                return;
            }

            textBox1.Text = "email sent.";

            success = await mailman.CloseSmtpConnectionAsync();
        }
Пример #2
0
        public MimeHelper(System.IO.Stream inputStream)
        {
            using (System.IO.StreamReader sr = new System.IO.StreamReader(inputStream, true))
            {
                string streamContents = sr.ReadToEnd();

                Chilkat.MailMan mailMan = new Chilkat();
                mailMan.UnlockComponent(@"WRKSHRMAILQ_cFSLZe4MnB2y");
                m_email = new Chilkat.Email();
                if (!m_email.SetFromMimeText(streamContents))
                    throw new ArgumentException();
            }
        }
Пример #3
0
        private void DisplatchMailTest2(interoperabilita.CalendarMail.MailRequest request)
        {
            bool success = false;

            Chilkat.MailMan server = new Chilkat.MailMan()
            {
                SmtpHost     = "freesmtp.valueteam.com",
                SmtpUsername = "",
                SmtpPassword = ""
            };

            Chilkat.Email mail = new Chilkat.Email()
            {
                Subject = "This is a iCal test",
                Body    = "This is a iCal test",
                From    = "Organizer <*****@*****.**>"
            };

            server.UnlockComponent(ChilkatKeys.Mail);

            success = mail.AddTo("Attendee", "*****@*****.**");
            if (success != true)
            {
                throw new Exception(mail.LastErrorText);
            }

            success = mail.AddiCalendarAlternativeBody(request.AppointmentAsText, "REQUEST");
            if (success != true)
            {
                throw new Exception(mail.LastErrorText);
            }

            success = server.SendEmail(mail);
            if (success != true)
            {
                throw new Exception(server.LastErrorText);
            }

            success = server.CloseSmtpConnection();
            if (success != true)
            {
                throw new Exception("Connection to SMTP server not closed cleanly.");
            }
        }
Пример #4
0
        private void sendPoster(string filename)
        {
            FileInfo f = new FileInfo(filename);
            string   local_filename = f.Name;

            Chilkat.MailMan mailman = new Chilkat.MailMan();
            bool            success;

            success = mailman.UnlockComponent("HAFSJOMAILQ_9QYSMgP0oR1h");
            if (success != true)
            {
                throw new Exception(mailman.LastErrorText);
            }

            //  Use the GMail SMTP server
            mailman.SmtpHost = Program.Smtphost;
            mailman.SmtpPort = int.Parse(Program.Smtpport);
            mailman.SmtpSsl  = bool.Parse(Program.Smtpssl);

            //  Set the SMTP login/password.
            mailman.SmtpUsername = Program.Smtpuser;
            mailman.SmtpPassword = Program.Smtppasswd;

            //  Create a new email object
            Chilkat.Email email = new Chilkat.Email();

            email.Subject = "Puls3060 Regnskab: " + local_filename;
            email.Body    = "Puls3060 Regnskab: " + local_filename;

            //email.AddTo(Program.MailToName, Program.MailToAddr);
            email.From    = Program.MailFrom;
            email.ReplyTo = Program.MailReply;
            email.AddBcc(Program.MailToName, Program.MailToAddr);

            email.AddFileAttachment(filename);
            email.UnzipAttachments();

            success = mailman.SendEmail(email);
            if (success != true)
            {
                throw new Exception(email.LastErrorText);
            }
        }
Пример #5
0
        public void sendRykkerEmail(string ToName, string ToAddr, string subject, string body)
        {
            Chilkat.MailMan mailman = new Chilkat.MailMan();
            bool            success;

            success = mailman.UnlockComponent("HAFSJOMAILQ_9QYSMgP0oR1h");
            if (success != true)
            {
                throw new Exception(mailman.LastErrorText);
            }

            //  Use the GMail SMTP server
            mailman.SmtpHost = Program.Smtphost;
            mailman.SmtpPort = int.Parse(Program.Smtpport);
            mailman.SmtpSsl  = bool.Parse(Program.Smtpssl);

            //  Set the SMTP login/password.
            mailman.SmtpUsername = Program.Smtpuser;
            mailman.SmtpPassword = Program.Smtppasswd;

            //  Create a new email object
            Chilkat.Email email = new Chilkat.Email();


#if (DEBUG)
            email.AddTo(Program.MailToName, Program.MailToAddr);
            email.Subject = "TEST " + subject + " skal sendes til: " + ToName + " " + ToAddr;
#else
            email.AddTo(ToName, ToAddr);
            email.Subject = subject;
            email.AddCC("Claus Knudsen", "*****@*****.**");
            email.AddBcc(Program.MailToName, Program.MailToAddr);
#endif
            email.Body    = body;
            email.From    = Program.MailFrom;
            email.ReplyTo = Program.MailReply;

            success = mailman.SendEmail(email);
            if (success != true)
            {
                throw new Exception(email.LastErrorText);
            }
        }
Пример #6
0
        public void overfoersel_mail(int lobnr)
        {
            var antal = (from c in Program.dbData3060.Tbltilpbs
                         where c.Id == lobnr
                         select c).Count();

            if (antal == 0)
            {
                throw new Exception("101 - Der er ingen PBS forsendelse for id: " + lobnr);
            }

            Chilkat.MailMan mailman = new Chilkat.MailMan();
            bool            success;

            success = mailman.UnlockComponent("HAFSJOMAILQ_9QYSMgP0oR1h");
            if (success != true)
            {
                throw new Exception(mailman.LastErrorText);
            }

            //  Use the GMail SMTP server
            mailman.SmtpHost = Program.Smtphost;
            mailman.SmtpPort = int.Parse(Program.Smtpport);
            mailman.SmtpSsl  = bool.Parse(Program.Smtpssl);

            //  Set the SMTP login/password.
            mailman.SmtpUsername = Program.Smtpuser;
            mailman.SmtpPassword = Program.Smtppasswd;

            var qrykrd = from k in Program.karMedlemmer
                         join h in Program.dbData3060.Tbloverforsel on k.Nr equals h.Nr
                         where h.Tilpbsid == lobnr
                         select new
            {
                k.Nr,
                k.Email,
                k.Kaldenavn,
                k.Navn,
                h.Betalingsdato,
                h.Advistekst,
                h.Advisbelob,
                h.Bankregnr,
                h.Bankkontonr,
            };


            // Start loop over betalinger i tbloverforsel
            int testantal = qrykrd.Count();

            foreach (var krd in qrykrd)
            {
                //  Create a new email object
                Chilkat.Email email = new Chilkat.Email();

#if (DEBUG)
                email.Subject = "TEST Bankoverførsel fra Puls 3060: skal sendes til " + Program.MailToName + " " + Program.MailToAddr;
                email.AddTo(Program.MailToName, Program.MailToAddr);
#else
                email.Subject = "Bankoverførsel fra Puls 3060";
                if (krd.Email.Length > 0)
                {
                    email.AddTo(krd.Navn, krd.Email);
                    email.AddBcc(Program.MailToName, Program.MailToAddr);
                }
                else
                {
                    email.Subject += ": skal sendes til " + krd.Navn;
                    email.AddTo(Program.MailToName, Program.MailToAddr);
                }
#endif
                email.Body = new clsInfotekst
                {
                    infotekst_id     = 40,
                    numofcol         = null,
                    kaldenavn        = krd.Kaldenavn,
                    betalingsdato    = krd.Betalingsdato,
                    advisbelob       = krd.Advisbelob,
                    bankkonto        = krd.Bankregnr + "-" + krd.Bankkontonr,
                    advistekst       = krd.Advistekst,
                    underskrift_navn = "\r\nMogens Hafsjold\r\nRegnskabsfører"
                }.getinfotekst();

                email.From    = Program.MailFrom;
                email.ReplyTo = Program.MailReply;

                success = mailman.SendEmail(email);
                if (success != true)
                {
                    throw new Exception(email.LastErrorText);
                }
            }
        }
        public static bool SendAnEmail()
        {
            bool success = false;

            //  The mailman object is used for sending and receiving email.
            Chilkat.MailMan mailman = new Chilkat.MailMan();

            success = mailman.UnlockComponent("SCOTTGMAILQ_ZpcR8r2N6R7a");

            if (success != true)
            {
                //Common.Log(_mailman.LastErrorText);
                return false;
            }

            if (isSsl)
            {
                mailman.SmtpSsl = true;
            }

            mailman.SmtpHost = smtpHost;

            if (smtpPort > 0)
            {
                mailman.SmtpPort = smtpPort;
            }

            //  Set the SMTP login/password (if required)
            mailman.SmtpUsername = smtpHostUserName;

            mailman.SmtpPassword = smtpHostPassword;

            //  Create a new email object
            Chilkat.Email email = new Chilkat.Email();

            email.Subject = emailSubject;

            if (isHtml)
            {
                email.SetHtmlBody(emailBody);
            }
            else
            {
                email.Body = emailBody;
            }
            email.FromName = emailFromFriendlyName;
            email.FromAddress = emailFromName;

            email.AddTo(emailToFriendlyName, emailToName);

            if (attachment.Length > 0)
            {
                //message.Attachments.Add(new System.Net.Mail.Attachment(_attachment1));
            }

            //  Call SendEmail to connect to the SMTP server and send.
            //  The connection (i.e. session) to the SMTP server remains
            //  open so that subsequent SendEmail calls may use the
            //  same connection.
            success = mailman.SendEmail(email);

            if (success)
            {
                return true;
            }
            else
            {
                Console.WriteLine(mailman.LastErrorText);
                return false;
            }
        }
        private void buttonSend_Click(object sender, EventArgs e)
        {

            if (txtTo.Text.Length == 0)
            {
                MessageBox.Show("Please Enter To Field",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (txtFrom.Text.Length == 0)
            {
                MessageBox.Show("Please Enter From Field",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (txtSubject.Text.Length == 0)
            {
                MessageBox.Show("Please Enter Subject Field",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            //  The mailman object is used for sending and receiving email.
            Chilkat.MailMan _mailman = new Chilkat.MailMan();

            _success = _mailman.UnlockComponent("SCOTTGMAILQ_ZpcR8r2N6R7a");

            //  Create a new email object
            Chilkat.Email _email = new Chilkat.Email();

            //  Set the SMTP server.
            _mailman.SmtpHost = System.Configuration
                .ConfigurationManager.AppSettings["smtpaddress"];
            _mailman.SmtpUsername = System.Configuration
                .ConfigurationManager.AppSettings["smtpid"];
            _mailman.SmtpPassword = System.Configuration
                .ConfigurationManager.AppSettings["smtppwd"];

            //  You may need a login/password.  In many cases,
            //  authentication is not required when sending local email
            //  (i.e. to email addresses having the same domain as the
            //  SMTP server), but is required when sending to non-local
            //  recipients.
            //mailman.SmtpUsername = "******";
            //mailman.SmtpPassword = "******";

            _email.Subject = txtSubject.Text;
            _email.Body = txtNote.Text;
            _email.From = txtFrom.Text;
            _email.AddTo(txtTo.Text, txtTo.Text);

            //Add any number of attachments:
            string contentType;

            contentType = _email.AddFileAttachment(_attachmentPath);

            _success = _mailman.SendEmail(_email);

            if (_success != true)
            {
                _errorMessage = _mailman.LastErrorText;
            }
            else
            {
                _sendEmail = FaxingServer.NewFaxingServer();
                _sendEmail.FaxNumber = "None";
                _sendEmail.FaxPageCount = 0;
                _sendEmail.FaxPath = _attachmentPath;
                _sendEmail.RecipientName = txtTo.Text;
                _sendEmail.DisplayName = txtFrom.Text;
                _sendEmail.Notes = "Subject: " + txtSubject.Text + " on " 
                        + DateTime.Now.ToShortDateString() 
                        + " at " + DateTime.Now.ToShortTimeString();

                _sendEmail.ShowFax = "N";
                _sendEmail.Save(); 
            }

            this.Close();  
        }
        public static bool SendAnEmail()
        {
            bool _success = false;

            //  The mailman object is used for sending and receiving email.
            Chilkat.MailMan _mailman = new Chilkat.MailMan();

            _success = _mailman.UnlockComponent("SCOTTGMAILQ_ZpcR8r2N6R7a");

            if (_success != true)
            {
                //Common.Log(_mailman.LastErrorText);
                return false;
            }

            if (_isSSL)
            {
                _mailman.SmtpSsl = true;
            }

            _mailman.SmtpHost = _smtpHost;

            if (_smtpPort > 0)
            {
                _mailman.SmtpPort = _smtpPort;
            }

            //  Set the SMTP login/password (if required)
            _mailman.SmtpUsername = _smtpHostUserName;

            _mailman.SmtpPassword = _smtpHostPassword;

            //  Create a new email object
            Chilkat.Email _email = new Chilkat.Email();

            _email.Subject = _emailSubject;

            if (_isHTML)
            {
                _email.SetHtmlBody(_emailBody);
            }
            else
            {
                _email.Body = _emailBody;
            }
            _email.FromName = _emailFromFriendlyName;
            _email.FromAddress = _emailFrom;

            _email.AddTo(_emailToFriendlyName, _emailTo);

            if (_attachment.Length > 0)
            {
                //message.Attachments.Add(new System.Net.Mail.Attachment(_attachment1));
            }

            //  Call SendEmail to connect to the SMTP server and send.
            //  The connection (i.e. session) to the SMTP server remains
            //  open so that subsequent SendEmail calls may use the
            //  same connection.
            _success = _mailman.SendEmail(_email);


            if (_success)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
Пример #10
0
		private void CreateImplementor()
		{
			if (null != m_mimeImplementor)
				return;

			Chilkat.MailMan mailMan = new Chilkat.MailMan();
            mailMan.UnlockComponent(@"WRKSHRMAILQ_cFSLZe4MnB2y");
			m_mimeImplementor = new Chilkat.Email();
		}
Пример #11
0
		private void Dispose(bool disposing)
		{
			if (m_disposed)
				return;

			if (disposing)
			{
				if (null != m_attachments)
				{
					m_attachments.Dispose();
					m_attachments = null;
				}

				if (null != m_mimeImplementor)
				{
					m_mimeImplementor.Dispose();
					m_mimeImplementor = null;
				}

				MimeSize = 0;
			}

			m_disposed = true;
		}
Пример #12
0
        private void ZipFiles(object sender, DoWorkEventArgs e)
        {
            DataTable dt          = VSWebBL.ConfiguratorBL.FeedbackBL.Ins.GetCompanyName();
            string    companyname = dt.Rows[0]["CompanyName"].ToString();

            object[] paramsToReceive = e.Argument as object[];


            string[] paths = paramsToReceive[0] as string[];

            //string paths = paramsToReceive[0].ToString();
            string emailAddressToSendTo = paramsToReceive[1] as string;

            string logPath = "";

            logPath = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("Log Files Path");
            if (logPath == "")
            {
                logPath = AppDomain.CurrentDomain.BaseDirectory.ToString();
            }
            try
            {
                string[] oldZipFiles = System.IO.Directory.GetFiles(logPath, "LogFiles.z*");
                foreach (string file in oldZipFiles)
                {
                    System.IO.File.Delete(file);
                }


                ZipFile zip = new ZipFile();

                zip.AddFiles(paths);
                zip.MaxOutputSegmentSize = 3 * 1024 * 1024;
                zip.Save(logPath + "LogFiles.zip");

                string[] zipFiles = System.IO.Directory.GetFiles(logPath, "LogFiles.z*");


                string host   = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("PrimaryHostName");
                string port   = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("primaryport");
                bool   auth   = Convert.ToBoolean(VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("primaryAuth").ToString());
                string PEmail = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("primaryUserID");
                string Ppwd   = VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("primarypwd");
                bool   PSSL   = Convert.ToBoolean(VSWebBL.SettingBL.SettingsBL.Ins.Getvalue("primarySSL").ToString());
                bool   gmail  = host.ToUpper().Contains("GMAIL");


                Chilkat.MailMan mailman = new Chilkat.MailMan();

                try
                {
                    mailman.UnlockComponent("MZLDADMAILQ_8nzv7Kxb4Rpx");
                }
                catch (Exception ex)
                {
                    Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Error unlocking chilkat. Exception - " + ex.Message);
                }

                mailman.SmtpPort = Convert.ToInt32(port);
                mailman.SmtpHost = host;

                if (auth)
                {
                    mailman.SmtpPassword = Ppwd;
                    mailman.SmtpUsername = PEmail;
                }

                if (gmail && mailman.SmtpPort != 587)
                {
                    mailman.SmtpPort = 587;
                    mailman.SmtpSsl  = true;
                }

                string errors = "";
                for (int i = 0; i < zipFiles.Length; i++)
                {
                    string file = zipFiles[i];

                    Chilkat.Email email = new Chilkat.Email();

                    //email.Body = "Log Files sent from " + Session["UserLogin"].ToString() + ".  File  " + (i + 1) + " of " + zipFiles.Length + ".";
                    email.Body    = "Feedback received from " + companyname + " Details: \n\rSubject: " + Session["subject"].ToString() + "\nType :" + Session["Type36"].ToString() + "\nMessage :" + Session[" Message"].ToString() + "\nStatus:" + Session["Status"].ToString() + "\nAttachments:" + Session["filepath"].ToString() + " ";
                    email.Subject = "VSPlus-Feedback:CompanyName:" + companyname + "";
                    email.AddTo("RPR Wyatt", emailAddressToSendTo);
                    email.FromAddress = PEmail;
                    email.FromName    = PEmail;

                    email.AddFileAttachment(file);
                    bool success = mailman.SendEmail(email);

                    if (!success)
                    {
                        email = new Chilkat.Email();

                        email.Body = "Attachements sent from " + Session["UserLogin"].ToString() + ".  File " + zipFiles[i] + " did not send due to an unknown error.";

                        email.Subject = "Log Files";
                        email.AddTo("RPR Wyatt", emailAddressToSendTo);
                        email.FromAddress = PEmail;
                        email.FromName    = PEmail;

                        mailman.SendEmail(email);
                        Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Error sending file " + zipFiles[i] + ".");

                        continue;
                    }
                    System.IO.File.Delete(file);
                }


                mailman.Dispose();
            }
            catch (Exception ex)
            {
                Log.Entry.Ins.WriteHistoryEntry(DateTime.Now.ToString() + " Error zipping log files. Exception - " + ex.Message);
            }
        }
Пример #13
0
        public void overfoersel_mail(int lobnr)
        {
            Chilkat.MailMan mailman = new Chilkat.MailMan();
            bool            success;

            success = mailman.UnlockComponent("HAFSJOMAILQ_9QYSMgP0oR1h");
            if (success != true)
            {
                throw new Exception(mailman.LastErrorText);
            }

            //  Use the GMail SMTP server
            mailman.SmtpHost = Program.Smtphost;
            mailman.SmtpPort = int.Parse(Program.Smtpport);
            mailman.SmtpSsl  = bool.Parse(Program.Smtpssl);

            //  Set the SMTP login/password.
            mailman.SmtpUsername = Program.Smtpuser;
            mailman.SmtpPassword = Program.Smtppasswd;

            XElement headxml = new XElement("OverforselMail");

            headxml.Add(new XElement("Lobnr", lobnr));
            clsRest   objRest    = new clsRest();
            string    strheadxml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> " + headxml.ToString();
            string    result     = objRest.HttpPost2(clsRest.urlBaseType.data, "overforselmail", strheadxml);
            XDocument xmldata    = XDocument.Parse(result);
            string    Status     = xmldata.Descendants("Status").First().Value;

            if (Status == "True")
            {
                var qry_email = from overforselemail in xmldata.Descendants("OverforselEmail")
                                select new
                {
                    Navn  = clsPassXmlDoc.attr_val_string(overforselemail, "Navn"),
                    Email = clsPassXmlDoc.attr_val_string(overforselemail, "Email"),
                    Tekst = clsPassXmlDoc.attr_val_string(overforselemail, "Tekst"),
                };
                foreach (var msg in qry_email)
                {
                    //  Create a new email object
                    Chilkat.Email email = new Chilkat.Email();

#if (DEBUG)
                    email.Subject = "TEST Bankoverførsel fra Puls 3060: skal sendes til " + Program.MailToName + " " + Program.MailToAddr;
                    email.AddTo(Program.MailToName, Program.MailToAddr);
#else
                    email.Subject = "Bankoverførsel fra Puls 3060";
                    if (msg.Email.Length > 0)
                    {
                        email.AddTo(msg.Navn, msg.Email);
                        email.AddBcc(Program.MailToName, Program.MailToAddr);
                    }
                    else
                    {
                        email.Subject += ": skal sendes til " + msg.Navn;
                        email.AddTo(Program.MailToName, Program.MailToAddr);
                    }
#endif
                    email.Body    = msg.Tekst;
                    email.From    = Program.MailFrom;
                    email.ReplyTo = Program.MailReply;

                    success = mailman.SendEmail(email);
                    if (success != true)
                    {
                        throw new Exception(email.LastErrorText);
                    }
                }
            }
        }
Пример #14
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="SmtpServer"></param>
        /// <param name="SmtpPort"></param>
        /// <param name="AccountMail"></param>
        /// <param name="AccountPwd"></param>
        /// <param name="FromName"></param>
        /// <param name="To"></param>
        /// <param name="CC"></param>
        /// <param name="Bcc"></param>
        /// <param name="Subject"></param>
        /// <param name="Body"></param>
        /// <param name="attachmentList"></param>
        /// <param name="Priority"></param>
        /// <param name="IsUseCredentials"></param>
        /// <param name="MainEncoding"></param>
        /// <param name="isHtml"></param>
        /// <param name="IsSSL"></param>
        /// <returns></returns>
        public static bool SendMailEx(string SmtpServer, int SmtpPort, string AccountMail, string AccountPwd, string FromName, string To, string CC, string Bcc, string Subject, string Body, IList <string> attachmentList, int Priority, bool IsUseCredentials, string MainEncoding, bool isHtml, bool IsSSL)
        {
            //过滤掉邮件帐号中的@以及域名
            if (AccountMail.Contains("@"))
            {
                AccountMail = AccountMail.Substring(0, AccountMail.IndexOf("@"));
            }
            //获取发件人邮箱
            string FromMail = string.Empty;

            if (SmtpServer.Contains(';'))
            {
                string[] SmtpServers = SmtpServer.Split(';');
                SmtpServer = SmtpServers[0];
                FromName   = AccountMail + "@" + SmtpServers[1].Substring(SmtpServers[1].IndexOf('.') + 1, SmtpServers[1].Length - SmtpServers[1].IndexOf('.') - 1);
            }
            else
            {
                FromMail = AccountMail + "@" + SmtpServer.Substring(SmtpServer.IndexOf('.') + 1, SmtpServer.Length - SmtpServer.IndexOf('.') - 1);
            }

            string ToName = To.Substring(0, To.IndexOf("@"));

            Chilkat.MailMan mailman = new Chilkat.MailMan();
            bool            success = mailman.UnlockComponent("MAILT34MB34N_6ADE5E140UIY");

            if (success != true)
            {
                return(false);
            }
            //设置SMTP服务器
            mailman.SmtpHost = SmtpServer;
            mailman.SmtpSsl  = IsSSL;
            mailman.SmtpPort = SmtpPort;

            //设置SMTP服务器登录信息
            mailman.SmtpUsername = AccountMail;
            mailman.SmtpPassword = AccountPwd;

            //创建一个Email对象
            Chilkat.Email email = new Chilkat.Email();
            email.Subject = Subject;
            email.Body    = Body;
            email.SetHtmlBody(Body);
            if (attachmentList != null)
            {
                // 附件
                foreach (string attachment in attachmentList)
                {
                    email.AddFileAttachment(attachment);
                }
            }
            email.From = "" + FromName + " <" + FromMail + ">";
            email.AddTo("" + ToName + "", To);

            success = mailman.SendEmail(email);
            mailman.CloseSmtpConnection();
            if (success != true)
            {
                return(false);
            }
            return(success);
        }
Пример #15
0
		// TODO: ProtectProcess - fix test, bring back mime
		//[Test]
		public void TestModifyMime()
		{
			IUniversalRequestObject uro = UroFromMimeBytes("TestPlainTextMessageBody");

			// Lets change some properties on the mime
			string mimeContent = uro.OriginalContentBytes.Data.AsString(uro.OriginalContentBytes.Data.Length, Encoding.Unicode);

			// Lets get ride of the old mime
			uro.OriginalContentBytes.Data.Dispose();

			// Now lets modify it.
			using (Chilkat.Email email = new Chilkat.Email())
			{
				email.SetFromMimeText(mimeContent);
				email.Subject = "Processed: " + email.Subject;
				email.AddTo("blackhole2", "*****@*****.**");
				email.AddCC("blackhole3", "*****@*****.**");
				email.AddBcc("blackhole4", "*****@*****.**");
				email.Body += " And don't forget it!";
				email.AddFileAttachment(TEST_FILE_PATH + @"\test.ppt");

				Assert.AreEqual(3, email.NumTo);
				Assert.AreEqual(2, email.NumCC);
				Assert.AreEqual(2, email.NumBcc);

				UnicodeEncoding encoding = new UnicodeEncoding();
				string modifiedMime = MimeProxy.InsertBccRecipientsIntoMime(email);
				MemoryStream mimeStream = new MemoryStream(encoding.GetBytes(modifiedMime));
				uro.OriginalContentBytes.Data = new Workshare.Policy.BinaryData(mimeStream);
			}

			// Lets synchronize the URO with the MIME.
			using (Stream str = uro.OriginalContentBytes.Data.AsStream())
			{
				MimeProxy mimeProxy = new MimeProxy(str);
				Email2Uro email2Uro = new Email2Uro(mimeProxy);
				email2Uro.Convert(RequestChannel.Outlook, uro);
			}

			//sender
			Assert.IsTrue(1 == uro.Source.Items.Count, "Should only be a single source item");
			Assert.AreEqual("*****@*****.**", uro.Source.Items[0].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("lnpair", uro.Source.Items[0].Properties[SMTPPropertyKeys.DisplayName], "Mismatch in email emailAddress");

			//recips
			Assert.AreEqual(7, uro.Destination.Items.Count);

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[0].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("Black Hole", uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[0].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 1 should be of AddressType: To");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[1].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("Pair Adm", uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[1].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 2 should be of AddressType: To");

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[2].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("lnpair", uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.CC, uro.Destination.Items[2].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Cc");

			Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.BCC, uro.Destination.Items[3].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");

			// New recipients added.
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[4].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole2", uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.To, uro.Destination.Items[4].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[5].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole3", uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.CC, uro.Destination.Items[5].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");
			Assert.AreEqual("*****@*****.**", uro.Destination.Items[6].Content, "Mismatch in email emailAddress");
			Assert.AreEqual("blackhole4", uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.DisplayName], "Mismatch in email emailAddress");
			Assert.AreEqual(AddressType.BCC, uro.Destination.Items[6].Properties[SMTPItemPropertyKeys.AddressType], "Destination item 3 should be of AddressType: Bcc");

			//attachments
			Assert.AreEqual(1, uro.Attachments.Count);
			Assert.AreEqual("test.ppt", uro.Attachments[0].Name, "Mismatch in attachment name");
			Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", uro.Attachments[0].ContentType, "Mismatch in attachment content type");
			Assert.IsTrue(0 < uro.Attachments[0].Data.Length, "Expected the attachments data length to be greater then zero");
			using (Stream str = uro.Attachments[0].Data.AsStream())
			{
				Assert.IsTrue(0 < str.Length, "Expected to find a non-empty stream");
			}

			//properties
			Assert.AreEqual(8, uro.Properties.Count);
			Assert.AreEqual(String.Empty, uro.Properties[MailMessagePropertyKeys.FileHeader], "Mismatch in Property");
			Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.Body], "Mismatch in Property");
			Assert.AreEqual("This body is plain text. And don't forget it!", uro.Properties[MailMessagePropertyKeys.FormattedBody], "Mismatch in Property");
			Assert.AreEqual("Processed: TestPlainTextMessageBody", uro.Properties[MailMessagePropertyKeys.Subject], "Mismatch in Property");
			Assert.AreEqual("Outlook", uro.Properties[SMTPPropertyKeys.RequestChannel], "Mismatch in Property");
			Assert.AreEqual("test.ppt ", uro.Properties[MailMessagePropertyKeys.Attachments], "Mismatch in Property");
			Assert.AreEqual("3", uro.Properties[MailMessagePropertyKeys.xPriority], "Mismatch in Property");

			uro.OriginalContentBytes.Data.Dispose();

			foreach (RequestAttachment ra in uro.Attachments)
			{
				ra.Dispose();
			}
		}
Пример #16
0
		public void TestInsertBccRecipientsIntoMime()
		{
			using (Chilkat.Email email = new Chilkat.Email())
			{
				email.AddBcc("blackhole1", "*****@*****.**");
				email.AddBcc("blackhole2", "*****@*****.**");

				UnicodeEncoding encoding = new UnicodeEncoding();
				string modifiedMime = MimeProxy.InsertBccRecipientsIntoMime(email);
				Assert.IsTrue(modifiedMime.Contains("\"blackhole1\" <*****@*****.**>, \"blackhole2\" <*****@*****.**>"));
			}
		}
Пример #17
0
    protected bool InstantEmail_RefundReport()
    {
        #region Chilkat MailMan
        using (Chilkat.MailMan mailman = new Chilkat.MailMan())
        {
            mailman.UnlockComponent("SGREENWOODMAILQ_FuY9K2d92R8F");
            mailman.SmtpHost = Connection.GetSmtpHost();
            #region Chilkat Email
            using (Chilkat.Email email = new Chilkat.Email())
            {
                int      tzOffSet = (DateTime.Now.IsDaylightSavingTime()) ? -4 : -5;
                DateTime dt       = DateTime.Parse(CreateDate.Text);
                DateTime dtNow    = DateTime.UtcNow;
                email.AddHeaderField("X-Priority", "1 (High)");
                email.Subject = "ARC Portal - Refund Report";
                email.AddHeaderField("DataExchange-Automated", "LMS_JobNotice JobID:03");
                email.AddHeaderField("Portal-Automated", "Script-ARCRR");

                String emailPath = "emails/";
                String emailFile = "portal_arc_refund_processed.html";
                String htmlBody  = "";

                //System.IO.StreamReader rdr = new StreamReader(Server.MapPath("~") + emailPath + emailFile);
                System.IO.StreamReader rdr = new StreamReader(Server.MapPath(emailPath + emailFile));
                htmlBody = rdr.ReadToEnd();
                rdr.Close();
                rdr.Dispose();

                #region Populate Lead Email Fields
                htmlBody = htmlBody.Replace("{agent_name}", Page.User.Identity.Name);
                htmlBody = htmlBody.Replace("{attempt_on}", " at " + dtNow.ToString("MM/dd/yyyy HH:mm:ss") + " - UTC");

                htmlBody = htmlBody.Replace("{refund_type}", RefundType.Value);
                htmlBody = htmlBody.Replace("{callid}", lblCallID.Text);
                htmlBody = htmlBody.Replace("{donation_date}", dt.ToString("MM/dd/yyyy HH:mm:ss"));
                htmlBody = htmlBody.Replace("{donationccinfoid}", lblExternalID.Text);
                htmlBody = htmlBody.Replace("{refund_status}", rplDecision.Text);
                htmlBody = htmlBody.Replace("{refund_reason}", refundReason.Text);

                htmlBody = htmlBody.Replace("{amount_donation}", AmountOriginal.Value);
                htmlBody = htmlBody.Replace("{amount_refund}", Amount.Text);
                htmlBody = htmlBody.Replace("{first_name}", FirstName.Text);
                htmlBody = htmlBody.Replace("{last_name}", LastName.Text);
                htmlBody = htmlBody.Replace("{card_num}", CardNumber.Text);

                htmlBody = htmlBody.Replace("{refund_message}", msgRefund);


                #endregion Populate Lead Email Fields
                #region Populate Standard Email Fields
                htmlBody = htmlBody.Replace("{script_time}", dtNow.ToString());
                if (DateTime.Now.IsDaylightSavingTime())
                {
                    htmlBody = htmlBody.Replace("{script_timezone}", String.Format("GMT {0} {1}", tzOffSet, "Eastern Daylight Time"));
                }
                else
                {
                    htmlBody = htmlBody.Replace("{script_timezone}", String.Format("GMT {0} {1}", tzOffSet, "Eastern Standard Time"));
                }
                #endregion Populate Standard Email Fields

                email.SetHtmlBody(htmlBody);
                if (Connection.GetConnectionType() == "Local")
                {
                    email.AddTo("Pehuen Test 1", "*****@*****.**");
                    email.AddTo("Carrie Stevenson", "*****@*****.**");
                }
                else
                {
                    email.AddTo("Pehuen ARC", "*****@*****.**");
                    email.AddTo("Carrie Stevenson", "*****@*****.**");
                    //email.AddCC("MIS", "*****@*****.**");
                    //email.AddBcc("Pehuen Scripts", "*****@*****.**");
                }
                email.BounceAddress = "*****@*****.**";
                email.FromName      = "ARC Portal";
                email.FromAddress   = "*****@*****.**";
                email.ReplyTo       = "*****@*****.**";
                bool success;
                success = mailman.SendEmail(email);
                if (success)
                {
                    // Update the action
                    return(true);
                }
                else
                {
                    // Do not update the action, the system will pick it up again
                    return(false);
                }
            }
            #endregion Chilkat Email
        }
        #endregion Chilkat MailMan
    }
Пример #18
0
        public SendEmail(string MedlemsNr, string IntNavn, string AfdMail, string FilePDF, string emailModt, string Kategori)
        {
            Chilkat.MailMan mailman = new Chilkat.MailMan();

            bool success = mailman.UnlockComponent("PROBITMAILQ_ckTyt6oroW8J");

            if (success != true)
            {
                MyVars.EmailSendtOK  = false;
                MyVars.MailFejltekst = "Licens problemer: " + mailman.LastErrorText;
                MyVars.emailBody     = "";
                MyVars.emailSubj     = "";
                return;
            }
            mailman.SmtpHost = "172.16.2.150";
            //  Set the SMTP login/password (if required)
            //mailman.SmtpUsername = "******";
            //mailman.SmtpPassword = "******";
            Chilkat.Email email = new Chilkat.Email();

            if (MedlemsNr != "")
            {
                if (Kategori != "")
                {
                    EGBoligData EGData    = new EGBoligData();
                    Mail        oMailData = EGData.GetMailData(Kategori); // her hentes mail-tekster fra EGBolig tabel
                    if (MyVars.emailSubj == "")
                    {
                        MyVars.emailSubj = oMailData.Emne;
                    }
                    MyVars.emailSubj = MyVars.emailSubj.Replace("[Selskab_Nr]", "099");
                    MyVars.emailSubj = MyVars.emailSubj.Replace("[Medlem_Nr]", MedlemsNr);
                    string emailBodyx = oMailData.Tekst;

                    emailBodyx = emailBodyx.Replace("[Medlem_Navn]", IntNavn);
                    emailBodyx = emailBodyx.Replace("[Bruger_Navn]", "");
                    if (MyVars.emailBody == "")
                    {
                        MyVars.emailBody += emailBodyx;
                    }
                }
                else
                {
                    MyVars.emailSubj = "Medlemsbrev fra Boligkontoret Danmark";
                    MyVars.emailBody = "Medlemsbrev fra Boligkontoret Danmark";
                }
            }

            if (Properties.Settings.Default.Common_PROD == false)
            {
                emailModt = Properties.Settings.Default.Common_Email_Testmodt;    //her sikres at alle emails sendes til kism (anvendes til test)
            }

            email.Subject = MyVars.emailSubj;
            email.Body    = MyVars.emailBody;
            email.From    = AfdMail;
            //emailModt = "*****@*****.**";
            email.AddBcc("", emailModt);

            if (FilePDF != "")
            {
                string contentType = email.AddFileAttachment(FilePDF);
                if (string.IsNullOrEmpty(contentType))
                {
                    MyVars.EmailSendtOK  = false;
                    MyVars.MailFejltekst = "Dokument kunne ikke vedhæftes e-mail pga. fejl: " + mailman.LastErrorText;
                    MyVars.emailBody     = "";
                    MyVars.emailSubj     = "";
                    return;
                }
            }

            success = mailman.SendEmail(email);
            if (success != true)
            {
                MyVars.EmailSendtOK = false;
                MyVars.emailBody    = "";
                MyVars.emailSubj    = "";
                return;
            }
            else
            {
                MyVars.EmailSendtOK  = true;
                MyVars.MailFejltekst = "";
            }

            success = mailman.CloseSmtpConnection();
            if (success != true)
            {
                MyVars.EmailSendtOK  = false;
                MyVars.MailFejltekst = "Connection fejl opstået ved afsendelse af e-mail: Connection to SMTP server not closed cleanly: " + mailman.LastErrorText;
            }
            MyVars.emailBody = "";
            MyVars.emailSubj = "";
        }
Пример #19
0
        public void TestModifyMimeUsingChilkatDirectly()
        {
            byte[] mimebytes = File.ReadAllBytes(Path.Combine(m_testPath, "TestPlainTextMessageBody"));
            using (MimeProxy proxy = new MimeProxy(mimebytes))
            {
                // Now lets modify it.
                using (Chilkat.Email email = new Chilkat.Email())
                {
                    email.SetFromMimeText(proxy.MimeContent);
                    email.Subject = "Processed: " + email.Subject;
                    email.AddTo("blackhole2", "*****@*****.**");
                    email.AddCC("blackhole3", "*****@*****.**");
                    email.AddBcc("blackhole4", "*****@*****.**");
                    email.Body += " And don't forget it!";
                    email.AddFileAttachment(Path.Combine(m_testPath, @"test.ppt"));

                    Assert.AreEqual(3, email.NumTo);
                    Assert.AreEqual(2, email.NumCC);
                    Assert.AreEqual(2, email.NumBcc);

                    proxy.MimeContent = MimeProxy.InsertBccRecipientsIntoMime(email);
                }

                Assert.AreEqual("*****@*****.**", proxy.Sender.EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("lnpair", proxy.Sender.Name, "Mismatch in email emailAddress");

                Assert.AreEqual(3, proxy.ToRecipients.Count);
                Assert.AreEqual(2, proxy.CcRecipients.Count);
                Assert.AreEqual(2, proxy.BccRecipients.Count);

                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[0].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("Black Hole", proxy.ToRecipients[0].Name, "Mismatch in email emailAddress");
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[1].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("Pair Adm", proxy.ToRecipients[1].Name, "Mismatch in email emailAddress");
                Assert.AreEqual("*****@*****.**", proxy.ToRecipients[2].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("blackhole2", proxy.ToRecipients[2].Name, "Mismatch in email emailAddress");

                Assert.AreEqual("*****@*****.**", proxy.CcRecipients[0].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("lnpair", proxy.CcRecipients[0].Name, "Mismatch in email emailAddress");
                Assert.AreEqual("*****@*****.**", proxy.CcRecipients[1].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("blackhole3", proxy.CcRecipients[1].Name, "Mismatch in email emailAddress");

                Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("*****@*****.**", proxy.BccRecipients[0].Name, "Mismatch in email emailAddress");
                Assert.AreEqual("*****@*****.**", proxy.BccRecipients[1].EmailAddress, "Mismatch in email emailAddress");
                Assert.AreEqual("blackhole4", proxy.BccRecipients[1].Name, "Mismatch in email emailAddress");

                Assert.AreEqual(1, proxy.Attachments.Count);

                Assert.AreEqual("test.ppt", proxy.Attachments[0].DisplayName, "Mismatch in attachment name");
                Assert.AreEqual("application/vnd.ms-powerpoint; name=test.ppt", proxy.Attachments[0].ContentType, "Mismatch in attachment content type");
                Assert.IsTrue(proxy.Attachments[0].FileName.Contains("test.ppt"), "Expected to find a non-empty stream");

                Assert.AreEqual("This body is plain text. And don't forget it!", proxy.FormattedBodyText, "Mismatch in Property");
                Assert.AreEqual("Processed: TestPlainTextMessageBody", proxy.Subject, "Mismatch in Property");
            }
        }
Пример #20
0
        public void getEmail(int emailNum)         //获取email_num封邮件,将邮件总数保存到all_num
        {
            bool success = mailman.UnlockComponent("30-day trial");

            if (success != true)
            {
                Console.WriteLine("Component unlock failed");
                return;
            }
            mailman.MailHost    = "smail.ecnu.edu.cn";
            mailman.PopUsername = userName;
            mailman.PopPassword = pwd;


            Chilkat.StringArray saUidls = null;
            //  Get the complete list of UIDLs
            saUidls = mailman.GetUidls();

            if (saUidls == null)
            {
                Console.WriteLine(mailman.LastErrorText);
                return;
            }

            //  Get the 10 most recent UIDLs
            //  The 1st email is the oldest, the last email is the newest
            //  (usually)
            int i;
            int n;
            int startIdx;

            //n = saUidls.Count;
            n = mailman.GetMailboxCount();
            if (n > emailNum)
            {
                startIdx = n - emailNum;
            }
            else
            {
                startIdx = 0;
            }

            Chilkat.StringArray saUidls2 = new Chilkat.StringArray();
            for (i = startIdx; i <= n - 1; i++)
            {
                saUidls2.Append(saUidls.GetString(i) /*string.Format("{0}@ecnu.cn", i + 2)*/);
            }

            //  Download in full the 10 most recent emails:
            Chilkat.EmailBundle bundle = null;

            bundle = mailman.FetchMultiple(saUidls2);
            if (bundle == null)
            {
                Console.WriteLine(mailman.LastErrorText);
                return;
            }

            Chilkat.Email email = null;
            int           count = 0;

            mailList = new mail[bundle.MessageCount];
            for (i = 0; i < bundle.MessageCount; i++)
            {
                email = bundle.GetEmail(i);
                DateTime time    = email.LocalDate;
                string   timeStr = time.ToString();
                mailList[count].fromAddress = email.FromAddress;
                mailList[count].fromName    = email.FromName;
                mailList[count].subject     = email.Subject;
                mailList[count].time        = timeStr;
                mailList[count].body        = email.Body;
                count++;
            }

            mailman.Pop3EndSession();

            all_num = n;

            return;
        }
        public async Task <ActionResult <Models.APICallResult> > sendDirectiveEMailMessage(int motionId)
        {
            SqlConnection objSqlConnection1 = null;
            SqlConnection objSqlConnection2 = null;
            SqlCommand    objSqlCommandGetMotionRecipients;
            SqlCommand    objSqlCommandUpdateMotionRecipient;
            SqlDataReader objSqlDataGetMotionRecipients;

            System.Text.StringBuilder sbCommandText;
            Chilkat.Mht     objChilkatMht;
            Chilkat.Email   objChilkatEmail;
            Chilkat.MailMan objChilkatMailMan;
            HashSet <int>   hsSentMotionRecipient;

            Models.APICallResult apiCallResult = new Models.APICallResult();

            try
            {
                objSqlConnection1 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]);
                await objSqlConnection1.OpenAsync();

                objSqlConnection2 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]);
                await objSqlConnection2.OpenAsync();

                sbCommandText = new System.Text.StringBuilder();
                sbCommandText.Append("UPDATE MotionRecipient ");
                sbCommandText.Append("  SET NotificationSent = 1 ");
                sbCommandText.Append("  WHERE MotionRecipientID = @MotionID ");

                objSqlCommandUpdateMotionRecipient             = objSqlConnection1.CreateCommand();
                objSqlCommandUpdateMotionRecipient.CommandText = sbCommandText.ToString();
                objSqlCommandUpdateMotionRecipient.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int));
                objSqlCommandUpdateMotionRecipient.CommandTimeout = 600;
                objSqlCommandUpdateMotionRecipient.Prepare();

                sbCommandText = new System.Text.StringBuilder();
                sbCommandText.Append("SELECT MR.MotionRecipientID, TR.TargetName, TR.ContactEMailAddress ");
                sbCommandText.Append("  FROM MotionRecipient MR INNER JOIN TargetRecipient TR ON MR.TargetRecipientID = TR.TargetRecipientID ");
                sbCommandText.Append("  WHERE MR.MotionID = @MotionID ");

                objSqlCommandGetMotionRecipients             = objSqlConnection2.CreateCommand();
                objSqlCommandGetMotionRecipients.CommandText = sbCommandText.ToString();
                objSqlCommandGetMotionRecipients.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int));
                objSqlCommandGetMotionRecipients.CommandTimeout = 600;

                objSqlCommandGetMotionRecipients.Parameters[0].Value = motionId;
                objSqlDataGetMotionRecipients = objSqlCommandGetMotionRecipients.ExecuteReader();

                if (objSqlDataGetMotionRecipients.HasRows)
                {
                    objChilkatMht     = new Chilkat.Mht();
                    objChilkatMailMan = new Chilkat.MailMan();

                    objChilkatMht.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE);
                    objChilkatMailMan.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE);

                    objChilkatMailMan.SmtpHost = this._configuration["AppSettings:SMTPHostName"];
                    objChilkatMailMan.SmtpPort = int.Parse(this._configuration["AppSettings:SMTPPort"]);

                    if (this._configuration["AppSettings:SMTPAuthenticate"] == "true")
                    {
                        objChilkatMailMan.SmtpUsername = this._configuration["AppSettings:SMTPUserName"];
                        objChilkatMailMan.SmtpPassword = this._configuration["AppSettings:SMTPPassword"];
                    }

                    objChilkatMailMan.SmtpSsl  = (this._configuration["AppSettings:SMTPUseSSL"] == "true");
                    objChilkatMailMan.StartTLS = (this._configuration["AppSettings:SMTPIssueStartTLS"] == "true");

                    if (!string.IsNullOrEmpty(this._configuration["AppSettings:SMTPLogonDomain"]))
                    {
                        objChilkatMailMan.SmtpLoginDomain = this._configuration["AppSettings:SMTPLogonDomain"];
                    }

                    string strBaseUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, Request.PathBase);
                    string strUrl     = string.Format("{0}/{1}/{2}/", strBaseUrl, "render/directiveEMailMessage", motionId);

                    objChilkatEmail = new Chilkat.Email();

                    objChilkatEmail.SetFromMimeText(objChilkatMht.GetEML(strUrl));

                    hsSentMotionRecipient = new HashSet <int>();
                    while (await objSqlDataGetMotionRecipients.ReadAsync())
                    {
                        objChilkatEmail.AddTo(objSqlDataGetMotionRecipients.GetString(1), objSqlDataGetMotionRecipients.GetString(2));
                        hsSentMotionRecipient.Add(objSqlDataGetMotionRecipients.GetInt32(0));
                    }       // while (await objSqlDataGetMotionRecipients.ReadAsync())

                    objChilkatEmail.From    = this._configuration["AppSettings:DirectiveEMailFromAccount"];
                    objChilkatEmail.Subject = this._configuration["AppSettings:DirectiveEMailSubjectText"];


                    //Chilkat.Task objChilkatTask = objChilkatMailMan.SendEmailAsync(objChilkatEmail);
                    //if (objChilkatTask.LastMethodSuccess)
                    if (objChilkatMailMan.SendEmail(objChilkatEmail))
                    {
                        foreach (int intMotionRecipientID in hsSentMotionRecipient)
                        {
                            objSqlCommandUpdateMotionRecipient.Parameters[0].Value = intMotionRecipientID;
                            await objSqlCommandUpdateMotionRecipient.ExecuteNonQueryAsync();
                        }
                    }
                    else
                    {
                        // PROGRAMMER's NOTE:  need to log error
                        return(StatusCode(StatusCodes.Status500InternalServerError, objChilkatMailMan.LastErrorText));
                    };
                }
                objSqlDataGetMotionRecipients.Close();

                apiCallResult.resultCode = APICallResult.RESULT_CODE_SUCCESS;

                return(Ok(apiCallResult));
            }
            catch (Exception ex1)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex1.Message));
            } finally
            {
                if (objSqlConnection1.State == System.Data.ConnectionState.Open)
                {
                    objSqlConnection1.Close();
                }
                if (objSqlConnection2.State == System.Data.ConnectionState.Open)
                {
                    objSqlConnection2.Close();
                }
            }
        }       // sendDirectiveEMailMessage()
        public static bool SendTheEmail()
        {
            bool _success = false;

            //  The mailman object is used for sending and receiving email.
            Chilkat.MailMan _mailman = new Chilkat.MailMan();

            _success = _mailman.UnlockComponent("SCOTTGMAILQ_ZpcR8r2N6R7a");

            if (_success != true)
            {
                //Common.Log(_mailman.LastErrorText);
                return false;
            }

            _mailman.SmtpHost = _smtpHost;

            if (_smtpPort > 0)
            {
                _mailman.SmtpPort = _smtpPort;
            }

            if (_isSSL)
            {
                _mailman.SmtpSsl = true;
            }


            _mailman.SmtpAuthMethod = "LOGIN";

            //ntlmDomain: ucfs.org
            //ntlmUsername: reminders
            //ntlmpassword: @ucfs*1

            _mailman.SmtpLoginDomain = "ucs-domain";
            _mailman.SmtpUsername = "******";
            _mailman.SmtpPassword = "******";



            //  Set the SMTP login/password (if required)
            //SmtpUsername
            //_mailman.SmtpLoginDomain = "ucfs.org";
            //_mailman.SmtpUsername = _smtpHostUserName;
            //_mailman.SmtpPassword = _smtpHostPassword;

            //  Create a new email object
            Chilkat.Email _email = new Chilkat.Email();

            _email.Subject = _emailSubject;

            if (_isHTML)
            {
                _email.SetHtmlBody(_emailBody);
            }
            else
            {
                _email.Body = _emailBody;
            }
            _email.FromName = _emailFromFriendlyName;
            _email.FromAddress = _emailFrom;
            _email.AddTo(_emailToFriendlyName, _emailTo);

            if (_attachment.Length > 0)
            {
                //message.Attachments.Add(new System.Net.Mail.Attachment(_attachment1));
            }

            //  Call SendEmail to connect to the SMTP server and send.
            //  The connection (i.e. session) to the SMTP server remains
            //  open so that subsequent SendEmail calls may use the
            //  same connection.
            _success = _mailman.SendEmail(_email);


            if (_success)
            {
                //Common.Log(" email was successful");
                return true;
            }
            else
            {

                string ss = _mailman.LastErrorText;
                Console.WriteLine(ss);
                Console.Write(_mailman.SmtpSessionLog);
                //Common.Log(dr.GetString(2) + " email was not successful");
                return false;
            }
        }
Пример #23
0
    protected void ForgotPassword_Email(String key, DateTime expire, String rtr_Name, String rtr_Email)
    {
        using (Chilkat.MailMan mailman = new Chilkat.MailMan())
        {
            //mailman.UnlockComponent("SGREENWOODMAILQ_FuY9K2d92R8F");
            //mailman.SmtpHost = Connection.GetSmtpHost();

            mailman.UnlockComponent("SGREENWOODMAILQ_FuY9K2d92R8F");
            mailman.SmtpHost     = Connection.SmtpHost();
            mailman.SmtpPort     = Int32.Parse(Connection.SmtpPort());
            mailman.SmtpUsername = Connection.SmtpUsername();
            mailman.SmtpPassword = Connection.SmtpPassword();
            mailman.StartTLS     = true;

            using (Chilkat.Email email = new Chilkat.Email())
            {
                email.Subject = "Greenwood & Hall Portal - Password Reset";

                String openEmail = Server.MapPath(".") + @"\emails\portal_email_password_reminder.html";

                System.IO.StreamReader rdr = new System.IO.StreamReader(System.IO.File.OpenRead(openEmail));
                String htmlBody            = rdr.ReadToEnd(); rdr.Close(); rdr.Dispose();
                String resetLink           = "https://portal.greenwoodhall.com/offline/resetting.aspx?k=" + key;
                htmlBody = htmlBody.Replace("{ResetLink}", resetLink);

                //{ResetLink}
                //{Expire_Date}
                htmlBody = htmlBody.Replace("{Expire_Date}", expire.ToString("MM/dd/yyyy"));
                //{Expire_Time}
                htmlBody = htmlBody.Replace("{Expire_Time}", expire.ToString("HH:mm:ss"));
                //{Expire_Zone}
                htmlBody = htmlBody.Replace("{Expire_Zone}", "PST");
                //{RequestTime}
                htmlBody = htmlBody.Replace("{RequestTime}", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
                //{RequestIP} myIP
                htmlBody = htmlBody.Replace("{RequestIP}", Connection.userIP());
                //{ScriptTimeZone}
                htmlBody = htmlBody.Replace("{ScriptTimeZone}", "PST");

                email.SetHtmlBody(htmlBody);
                //email.AddTo("Pehuen Test", "*****@*****.**");
                email.AddTo(rtr_Name, rtr_Email);

                email.BounceAddress = "*****@*****.**";
                email.FromName      = "Greenwood & Hall Portal";
                email.FromAddress   = "*****@*****.**";
                email.ReplyTo       = "*****@*****.**";
                bool success;
                success = mailman.SendEmail(email);
                if (success)
                {
                    Label2.Text += "<br />Email Sent";
                    //Label2.Text += "<br />" + mailman.LastSmtpStatus;

                    lblLoginMessage.Text  = Label2.Text;
                    lblLoginMessage.Text += "<br />Please check your inbox within a few minutes for a link to reset your password.";

                    Panel1.Visible = true;
                    Panel2.Visible = false;
                }
                else
                {
                    Label2.Text += "<br />Email Failed, internal server error, please try again.";
                }
                //Label2.Text += "<br />" + Connection.GetSmtpHost();
                //Label2.Text += "<br />" + DateTime.Now.ToString("MM/dd/yyyy");
                //Label2.Text += "<br />" + DateTime.Now.ToString("HH:mm:ss");
            }
        }
    }