示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <param name="blockSize">Avoid increasing this too much. Keep below 128K (optimal). See MSDN notes for ReadText</param>
        /// <returns></returns>
        public static string GetMessageText(this CDO.Message message, int blockSize)
        {
            ADODB._Stream stream = message.GetStream();

            int size = (int)stream.Size;

            if (size <= blockSize)
            {
                return(stream.ReadText(size));
            }

            int           countRead = 0;
            string        block     = null;
            StringBuilder builder   = new StringBuilder(size);

            while (countRead < size)
            {
                block = stream.ReadText(blockSize);
                if (string.IsNullOrEmpty(block))
                {
                    break;
                }
                builder.Append(block);
                countRead += block.Length;
            }

            return(builder.ToString());
        }
示例#2
0
 public CDOSmtpMessage(CDO.Message message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     m_message = message;
 }
示例#3
0
        public void ProcessMessage(string[] args)
        {
            IOFiles files = new IOFiles(args);

            CDO.Message message = Extensions.LoadCDOMessageFromText(files.Read());
            this.Agent.ProcessMessage(message);
            files.Write(message.GetMessageText());
        }
示例#4
0
 public CDOSmtpMessage(CDO.Message message)
 {
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     m_message = message;
 }
示例#5
0
        public static void SetEnvelopeField(this CDO.Message message, string name, string value)
        {
            Fields fields = message.GetEnvelopeFields();

            if (fields != null && fields.Count > 0)
            {
                fields.SetValue(name, value);
            }
        }
示例#6
0
        public static void SetMessageStatus(this CDO.Message message, CdoMessageStat status)
        {
            Fields fields = message.GetEnvelopeFields();

            if (fields == null || fields.Count == 0)
            {
                return;
            }
            fields.SetValue(EnvelopeField_Status, status);
        }
示例#7
0
 public EML()
 {
     msg = new CDO.Message();
     stm = new ADODB.Stream();
     stm.Open(System.Reflection.Missing.Value,
              ADODB.ConnectModeEnum.adModeUnknown,
              ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
              "", "");
     stm.Type = ADODB.StreamTypeEnum.adTypeBinary;
 }
示例#8
0
        public static string GetHeader(this CDO.Message message, string name)
        {
            Fields fields = message.Fields;

            if (fields == null || fields.Count == 0)
            {
                return(null);
            }

            return(fields.GetStringValue(name));
        }
示例#9
0
        public static string GetEnvelopeField(this CDO.Message message, string name)
        {
            Fields fields = message.GetEnvelopeFields();

            if (fields == null || fields.Count == 0)
            {
                return(null);
            }

            return(fields.GetStringValue(name));
        }
示例#10
0
        public static CDO.Message LoadCDOMessageFromText(string text)
        {
            CDO.Message message = new CDO.Message();

            ADODB._Stream stream = message.GetStream();

            stream.Position = 0;
            stream.WriteText(text, StreamWriteEnum.stWriteChar);
            stream.SetEOS();
            stream.Flush();

            return message;
        }
示例#11
0
        public static CDO.Message LoadCDOMessageFromText(string text)
        {
            CDO.Message message = new CDO.Message();

            ADODB._Stream stream = message.GetStream();

            stream.Position = 0;
            stream.WriteText(text, StreamWriteEnum.stWriteChar);
            stream.SetEOS();
            stream.Flush();

            return(message);
        }
示例#12
0
        public static void Send(this Health.Direct.Common.Mail.Message message, string smtpServer, int port)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (string.IsNullOrEmpty(smtpServer))
            {
                throw new ArgumentException("smtpServer");
            }

            CDO.Message cdoMessage = LoadCDOMessageFromText(MimeSerializer.Default.Serialize(message));
            cdoMessage.Send(smtpServer, port);
        }
示例#13
0
        public static Fields GetEnvelopeFields(this CDO.Message message)
        {
            Fields fields = null;

            try
            {
                fields = message.EnvelopeFields;
            }
            catch
            {
            }

            return(fields);
        }
示例#14
0
        /// <summary>
        /// Send this message using the given Smtp Server
        /// </summary>
        /// <param name="message">outgoing message</param>
        /// <param name="smtpServer">smtp server to use</param>
        /// <param name="port">smtp port to use</param>
        public static void Send(this CDO.Message message, string smtpServer, int port)
        {
            if (string.IsNullOrEmpty(smtpServer))
            {
                throw new ArgumentException("smtpServer");
            }

            Fields configFields = message.Configuration.Fields;

            configFields.SetValue("http://schemas.microsoft.com/cdo/configuration/smtpserver", smtpServer);
            if (port > 0) // If <= 0, use default
            {
                configFields.SetValue("http://schemas.microsoft.com/cdo/configuration/smtpserverport", port);
            }
            configFields.SetValue("http://schemas.microsoft.com/cdo/configuration/sendusing", CDO.CdoSendUsing.cdoSendUsingPort);
            message.Send();
        }
示例#15
0
        static void Main(string[] args)
        {
            string emlPath = String.Empty;

            if (args.Length > 0)
            {
                emlPath = args[0].ToString();

                string emlContent = new StreamReader(emlPath).ReadToEnd();

                CDO.Message m = new CDO.Message();
                ADODB.Stream s = new ADODB.Stream();

                s = m.GetStream();
                s.Type = ADODB.StreamTypeEnum.adTypeText;
                s.LoadFromFile(emlPath);
                s.Flush();

                if (m.To.IndexOf(ConfigurationManager.AppSettings["addressPhotos"]) >= 0)
                {
                    foreach (IBodyPart bp in m.BodyPart.BodyParts)
                    {
                        if (bp.ContentMediaType == "image/jpeg")
                        {
                            string tempFilePath = ConfigurationManager.AppSettings["temporaryFilePath"] + System.Guid.NewGuid() + ".jpg";
                            bp.GetDecodedContentStream().SaveToFile(tempFilePath, SaveOptionsEnum.adSaveCreateOverWrite);

                            StreamReader sr = new StreamReader(tempFilePath);
                            Photo p = new Photo(bp.ContentMediaType, sr.BaseStream, m.Subject, m.TextBody, String.Empty);

                            // Pass up the sending and recipient addresses as well
                            p.SenderAddress = m.Sender;
                            p.RecipientAddress = m.To;

                            // Save the image
                            p.Save();

                            sr.Dispose();
                            File.Delete(tempFilePath);
                        }
                    }
                }

                s.Close();
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            dynamic objMail = new CDO.Message();

            try
            {
                dynamic      fromAddress  = "*****@*****.**";
                const string fromPassword = "******";
                dynamic      toAddress    = "*****@*****.**";
                string       subject      = "Test";
                dynamic      EnableSsl    = true;
                dynamic      smtpServer   = "smtp.exmail.qq.com";
                dynamic      smtpPort     = "465";
                string       body         = "" + "\r\n";
                body += "------------------------------------TrustPLus Contact Page Email------------------------------------" + "\r\n";
                body += "Customer Name: " + txtName.Text + "\r\n";
                body += "Customer Cell: " + txtPhoneNumber.Text + "\r\n";
                body += "Customer Email: " + txtEmail.Text + "\r\n";
                body += "Title: " + "正信网站客户信息" + "\r\n";
                body += "---------" + "\r\n";
                body += "Message: " + txtEmailMessage.Text;
                //here on button click what will done
                //SendMail()
                objMail.To      = toAddress;
                objMail.From    = fromAddress;
                objMail.Subject = subject;
                //objMail.HTMLBody = body
                objMail.TextBody = body;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value            = smtpPort;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value                = smtpServer;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendemailaddress").Value          = fromAddress;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress").Value = toAddress;
                //objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpaccountname").Value = fromAddress
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value     = fromAddress;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value     = fromPassword;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value        = 2;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1;
                objMail.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl").Value       = EnableSsl;
                objMail.Configuration.Fields.Update();
                objMail.Send();
            }
            catch (Exception)
            {
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
        }
示例#17
0
        public static void SetMessageText(this CDO.Message message, string messageText, bool save)
        {
            ADODB._Stream stream = message.GetStream();

            stream.Position = 0;
            stream.WriteText(messageText, StreamWriteEnum.stWriteChar);
            stream.SetEOS();
            stream.Flush();
            if (save)
            {
                try
                {
                    message.DataSource.Save();
                }
                catch
                {
                }
            }
        }
示例#18
0
        MessageEnvelope CreateEnvelope(CDO.Message message)
        {
            DirectAddressCollection recipientAddresses = null;
            DirectAddress           senderAddress      = null;
            MessageEnvelope         envelope;

            string messageText = message.GetMessageText();

            if (this.ExtractEnvelopeFields(message, ref recipientAddresses, ref senderAddress))
            {
                envelope = new MessageEnvelope(messageText, recipientAddresses, senderAddress);
            }
            else
            {
                envelope = new MessageEnvelope(messageText);
            }

            return(envelope);
        }
        //
        // Processing message like smtp gateway would
        //
        CDO.Message RunEndToEndTest(CDO.Message message, SmtpAgent agent)
        {
            agent.ProcessMessage(message);
            message = LoadMessage(message);
            VerifyOutgoingMessage(message);

            agent.ProcessMessage(message);
            message = LoadMessage(message);

            if (agent.Settings.InternalMessage.EnableRelay)
            {
                VerifyIncomingMessage(message);
            }
            else
            {
                VerifyOutgoingMessage(message);
            }
            return(message);
        }
示例#20
0
        public void ProcessEndtoEnd(string[] args)
        {
            IOFiles files = new IOFiles(args);

            //
            // Outgoing
            //
            CDO.Message outgoing = Extensions.LoadCDOMessageFromText(files.Read());
            this.Agent.ProcessMessage(outgoing);
            //
            // Incoming
            //
            CDO.Message incoming = Extensions.LoadCDOMessageFromText(outgoing.GetMessageText());
            this.Agent.ProcessMessage(incoming);
            //
            // Persist
            //
            files.Write(incoming.GetMessageText());
        }
示例#21
0
        /// <summary>
        /// 发送激活邮件
        /// </summary>
        /// <param name="addresser">发件人地址</param>
        /// <param name="addressPsswd">发件人密码</param>
        /// <param name="recipient">收件人地址</param>
        /// <param name="VerifyCode">随机验证码</param>
        public static void CDOMessageSend(string addresser, string addressPsswd, string recipient, string VerifyCode)
        {
            try
            {
                CDO.Message objMail = new CDO.Message();
                try
                {
                    objMail.To      = recipient;
                    objMail.From    = new MimeMailAddress(addresser, "深圳凯华技术有限公司").ToString();
                    objMail.Subject = "激活邮件";//邮件主题string strHTML = @"";

                    ////邮件正文
                    StringBuilder Content = new StringBuilder();
                    Content.Append("请进行邮箱验证,点击下面的链接激活您的邮箱,10分钟内有效:<br><a target='_blank' rel='nofollow' style='color: #0041D3; text-decoration: underline' href=http://120.78.49.234/MerchantPlatformApi/v/" + VerifyCode + ">点击这里</a>");

                    objMail.HTMLBody = Content.ToString();                                                                                //邮件内容
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value            = 465; //设置端口
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value                = "smtp.mxhichina.com";
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value          = addresser;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress"].Value = addresser;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value           = addresser;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value              = addresser;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value              = addressPsswd;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value        = 2;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
                    objMail.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value       = "true";//这一句指示是否使用ssl
                    objMail.Configuration.Fields.Update();
                    objMail.Send();
                }
                catch (Exception ex) { throw ex; }
                finally { }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(objMail);
                objMail = null;
            }
            catch (MissingMethodException ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#22
0
        //
        // A CDO Message could be arriving via the SMTP server, or could have been constructed manually
        // The one created by SMTP has envelope information
        // Returns false if no envelope info is available. We have to look within message headers in that case
        //
        bool ExtractEnvelopeFields(CDO.Message message, ref DirectAddressCollection recipientAddresses, ref DirectAddress senderAddress)
        {
            if (!this.HasEnvelope)
            {
                //
                // No envelope
                //
                return(false);
            }

            recipientAddresses = null;
            senderAddress      = null;

            string sender = message.GetEnvelopeSender();

            if (string.IsNullOrEmpty(sender))
            {
                throw new SmtpAgentException(SmtpAgentError.NoSenderInEnvelope);
            }
            //
            // In SMTP Server, the MAIL TO (sender) in the envelope can be empty if the message is from the server postmaster
            // The actual postmaster address is found in the message itself
            //
            if (Health.Direct.SmtpAgent.Extensions.IsSenderLocalPostmaster(sender))
            {
                return(false);
            }
            string recipients = message.GetEnvelopeRecipients();

            if (string.IsNullOrEmpty(recipients))
            {
                throw new SmtpAgentException(SmtpAgentError.NoRecipientsInEnvelope);
            }

            recipientAddresses = DirectAddressCollection.ParseSmtpServerEnvelope(recipients);
            senderAddress      = new DirectAddress(sender);

            return(true);
        }
示例#23
0
        public void SendEmail(string emailTo, string emailCC, string subjects, string body, string attachmentStream, string attachementFileName)
        {
            try
            {
                CDO.Message   oMsg = new CDO.Message();
                Configuration conf = new ConfigurationClass();
                conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value  = CdoSendUsing.cdoSendUsingPort;
                conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
                conf.Fields[CdoConfiguration.cdoSMTPUseSSL].Value       = true;
                conf.Fields[CdoConfiguration.cdoSMTPServer].Value       = "smtp.163.com";              //必填,而且要真实可用
                conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value   = "465";                       //465特有
                conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value = "<" + "*****@*****.**" + ">";
                conf.Fields[CdoConfiguration.cdoSendUserName].Value     = "*****@*****.**"; //真实的邮件地址
                conf.Fields[CdoConfiguration.cdoSendPassword].Value     = "asdqwe123";                 //为邮箱密码,必须真实
                conf.Fields.Update();

                oMsg.Configuration = conf;

                // oMsg.TextBody = System.Text.Encoding.UTF8;
                //Message.BodyEncoding = System.Text.Encoding.UTF8;
                oMsg.BodyPart.Charset = "utf-8";
                oMsg.HTMLBody         = body;
                oMsg.Subject          = subjects;
                oMsg.From             = "*****@*****.**";
                oMsg.To = emailTo;
                oMsg.CC = emailCC;
                //ADD attachment.
                //TODO: Change the path to the file that you want to attach.
                //oMsg.AddAttachment("C:\Hello.txt", "", "");
                //oMsg.AddAttachment("C:\Test.doc", "", "");
                oMsg.Send();
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                throw ex;
            }
            //System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
            //client.Host = "smtp.163.com";//使用163的SMTP服务器发送邮件
            //client.Port = 465;
            ////client.UseDefaultCredentials = true   ;
            //client.UseDefaultCredentials = true;
            //client.Timeout = 5000;
            //client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
            //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "asdqwe123");
            ////这里假定你已经拥有了一个163邮箱的账户,用户名为abc,密码为*******
            //System.Net.Mail.MailMessage Message = new System.Net.Mail.MailMessage();
            //Message.From = new System.Net.Mail.MailAddress("*****@*****.**");//这里需要注意,163似乎有规定发信人的邮箱地址必须是163的,而且发信人的邮箱用户名必须和上面SMTP服务器认证时的用户名相同
            ////因为上面用的用户名abc作SMTP服务器认证,所以这里发信人的邮箱地址也应该写为[email protected]
            ////Message.To.Add("*****@*****.**");//将邮件发送给Gmail
            //Message.To.Add(emailTo);//将邮件发送给QQ邮箱
            //if (!string.IsNullOrEmpty(emailCC))
            //{
            //    Message.CC.Add(emailCC);
            //}
            //Message.Subject = subjects;
            //Message.Body = body;
            //// Message.Attachments.Add(new System.Net.Mail.Attachment(@"C:\Workspace\com.yrtech.Bentley\com.yrtech.bentleyAPI\com.yrtech.InventoryAPI\Content\Excel\LeadsReport.xlsx", System.Net.Mime.MediaTypeNames.Application.Octet));
            //Message.SubjectEncoding = System.Text.Encoding.UTF8;
            //Message.BodyEncoding = System.Text.Encoding.UTF8;
            //Message.Priority = System.Net.Mail.MailPriority.High;
            //Message.IsBodyHtml = true;
            //CommonHelper.log("Email:"+emailTo + " " + subjects);
            //Thread.Sleep(500);
            //client.Send(Message);
        }
示例#24
0
        public static void CopyMessage(this CDO.Message message, string folderPath)
        {
            string fileName = CreateUniqueFileName();

            message.SaveToFile(Path.Combine(folderPath, fileName));
        }
 void RunMdnOutBoundProcessingTest(CDO.Message message, SmtpAgent agent)
 {
     VerifyMdnIncomingMessage(message); //Plain Text
     agent.ProcessMessage(message);     //Encrypts
     VerifyOutgoingMessage(message);    //Mdn looped back
 }
示例#26
0
        static void Main(string[] args)
        {
            EmailInfoRepository ei   = new EmailInfoRepository();
            EmailInfoEntity     info = ei.Get("27");

            try
            {
                #region 设置基本信息
                CDO.Message oMsg = new CDO.Message();

                Configuration conf = new ConfigurationClass();
                conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value  = CdoSendUsing.cdoSendUsingPort;
                conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
                conf.Fields[CdoConfiguration.cdoSMTPUseSSL].Value       = false;
                conf.Fields[CdoConfiguration.cdoSMTPServer].Value       = "smtp.sina.com";//必填,而且要真实可用
                conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value   = 25;
                conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value = "*****@*****.**";
                conf.Fields[CdoConfiguration.cdoSendUserName].Value     = "*****@*****.**"; //真实的邮件地址
                conf.Fields[CdoConfiguration.cdoSendPassword].Value     = "5e5d277c167bd275";     //为邮箱密码,必须真实
                //5e5d277c167bd275
                conf.Fields.Update();
                oMsg.Configuration = conf;
                #endregion 设置基本信息

                #region htmlbody

                string        bodyStr = "test11";
                List <string> strList = MailHelper.GetHtmlImageUrlList(bodyStr);
                Dictionary <string, string> dicImage = new Dictionary <string, string>();
                foreach (var str in strList)
                {
                    string key    = Guid.NewGuid().ToString();
                    string newUrl = "cid:" + key;
                    bodyStr = bodyStr.Replace(str, newUrl);
                    dicImage.Add(key, str);
                }
                oMsg.HTMLBody = info.EmailFilePath;

                #endregion
                StringBuilder title = new StringBuilder();
                title.Append("=?BIG5?B?");
                title.Append(ToBase64("titleTest"));
                title.Append("?=");
                oMsg.Subject = title.ToString();
                oMsg.From    = "\"" + "River" + "\"" + "*****@*****.**";
                ;//真实的邮件地址
                #region BCC
                StringBuilder bccs = new StringBuilder();
                bccs.Append("[email protected];");


                oMsg.BCC = bccs.ToString();
                #endregion BCC
                oMsg.HTMLBodyPart.Charset = "BIG5";


                oMsg.Send();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#27
0
 public static bool HasEnvelopeFields(this CDO.Message message)
 {
     return(message.GetEnvelopeFields() != null);
 }
示例#28
0
 public static string GetEnvelopeRecipients(this CDO.Message message)
 {
     return(message.GetEnvelopeField(EnvelopeField_Recipients));
 }
示例#29
0
        public void SendEmail(EmailInfo emailInfo, EmailAccount emailAccount, List <EmailSendBccAccount> toMails, List <EmailSendBccAccount> successList = null, List <EmailSendBccAccount> FailureList = null)
        {
            try
            {
                #region 设置基本信息
                CDO.Message oMsg = new CDO.Message();

                Configuration conf = new ConfigurationClass();
                conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value  = CdoSendUsing.cdoSendUsingPort;
                conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
                conf.Fields[CdoConfiguration.cdoSMTPUseSSL].Value       = false;
                conf.Fields[CdoConfiguration.cdoSMTPServer].Value       = emailAccount.EmailAccountSMTP;//必填,而且要真实可用
                conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value   = emailAccount.EmailAccountSMTPPort;
                conf.Fields[CdoConfiguration.cdoSendEmailAddress].Value = emailAccount.EmailAccountAddress;
                conf.Fields[CdoConfiguration.cdoSendUserName].Value     = emailAccount.EmailAccountAddress;  //真实的邮件地址
                conf.Fields[CdoConfiguration.cdoSendPassword].Value     = emailAccount.EmailAccountPassWord; //为邮箱密码,必须真实

                conf.Fields.Update();
                oMsg.Configuration = conf;
                #endregion 设置基本信息

                #region htmlbody

                string        bodyStr = emailInfo.EmailFilePath;
                List <string> strList = MailHelper.GetHtmlImageUrlList(bodyStr);
                Dictionary <string, string> dicImage = new Dictionary <string, string>();
                foreach (var str in strList)
                {
                    string key    = Guid.NewGuid().ToString();
                    string newUrl = "cid:" + key;
                    bodyStr = bodyStr.Replace(str, newUrl);
                    dicImage.Add(key, str);
                }
                oMsg.HTMLBody = bodyStr;
                #endregion
                StringBuilder title = new StringBuilder();
                title.Append("=?BIG5?B?");
                title.Append(ToBase64(emailInfo.EmailTitle));
                title.Append("?=");
                oMsg.Subject = title.ToString();
                oMsg.From    = "\"" + emailAccount.EmailAccountName + "\"" + emailAccount.EmailAccountAddress;
                ;//真实的邮件地址
                #region BCC
                StringBuilder bccs = new StringBuilder();
                foreach (EmailSendBccAccount to in toMails)
                {
                    try
                    {
                        //还要加上邮箱的正确性检验
                        if (!string.IsNullOrEmpty(to.EmailBccAccountInfo.EmailBccAccountAddress)) //&& MailHelper.IsEmail(to.EmailBccAccountInfo.EmailBccAccountAddress))
                        {
                            bccs.Append(to.EmailBccAccountInfo.EmailBccAccountAddress + ";");
                            successList.Add(to);
                        }
                        else
                        {
                            FailureList.Add(to);
                        }
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Error("Panther.Email.Services.SendEmail.CDOSendEmail", "SetBcc", ex.Message, ex);
                        FailureList.Add(to);
                    }
                }

                oMsg.BCC = bccs.ToString();
                LogHelper.Info(string.Format("發送郵箱:{0},收件箱:{1}", oMsg.From, oMsg.BCC));
                #endregion BCC
                oMsg.HTMLBodyPart.Charset = "BIG5";

                foreach (var imgUrl in dicImage)
                {
                    oMsg.AddRelatedBodyPart(imgUrl.Value, imgUrl.Key, CdoReferenceType.cdoRefTypeId);
                }

                oMsg.Send();
            }
            catch (Exception ex)
            {
                successList.Clear();
                FailureList = toMails;
                LogHelper.Error("Panther.Email.Services.SendEmail.CDOSendEmail", "SendEmail", ex.Message, ex);
                throw ex;
            }
        }
示例#30
0
 public static void SetEnvelopeRecipients(this CDO.Message message, MailAddressCollection recipients)
 {
     message.SetEnvelopeField(EnvelopeField_Recipients, recipients.ToSmtpServerEnvelopeAddresses());
 }
示例#31
0
 public static void SetEnvelopeRecipients(this CDO.Message message, string recipients)
 {
     message.SetEnvelopeField(EnvelopeField_Recipients, recipients);
 }
示例#32
0
 public static void SaveToFile(this CDO.Message message, string filePath)
 {
     ADODB._Stream stream = message.GetStream();
     stream.SaveToFile(filePath, SaveOptionsEnum.adSaveCreateOverWrite);
 }
示例#33
0
 public static string GetEnvelopeSender(this CDO.Message message)
 {
     return(message.GetEnvelopeField(EnvelopeField_Sender));
 }
示例#34
0
 private bool SendMail(string to, string subject, string url, MailConfig pmc)
 {
     DateTime before = DateTime.Now;
     try
     {
         CDO.Message msg = new CDO.Message();
         CDO.Configuration conf = msg.Configuration;
         Fields fs = conf.Fields;
         #region Set field values
         fs["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = "hu";
         fs["http://schemas.microsoft.com/cdo/configuration/postusing"].Value = CdoPostUsing.cdoPostUsingPort;
         fs["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = pmc.sendemailaddress;
         fs["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = pmc.sendpassword;
         fs["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = pmc.sendusername;
         fs["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = CdoSendUsing.cdoSendUsingPort;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "Zoznam";
         fs["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = CdoProtocolsAuthentication.cdoBasic;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value = 10;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = pmc.smtpserver;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = pmc.smtpport;
         fs["http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext"].Value = true;
         fs["http://schemas.microsoft.com/cdo/configuration/smtpusessl"].Value = false;
         fs["urn:schemas:calendar:timezoneid"].Value = CdoTimeZoneId.cdoEasternEurope;
         #endregion
         fs.Update();
         msg.Subject = subject;
         Trace.WriteLine("Downloading email body from feed page...");
         lblSendStatus.Text = "Send status: Downloading email body from feed page...";
         msg.CreateMHTMLBody(url, CdoMHTMLFlags.cdoSuppressNone, null, null);
         msg.To = to;
         Trace.WriteLine("Sending message...");
         lblSendStatus.Text = "Send status: Sending message...";
         msg.Send();
         TimeSpan total = DateTime.Now.Subtract(before);
         Trace.WriteLine("Message sent successfully. Total time: " + total.ToString());
         lblSendStatus.Text = "Send status: Message sent successfully. Total time: " + total.ToString();
         return true;
     }
     catch (COMException cex)
     {
         Trace.WriteLine(cex.ToString());
         return false;
     }
 }
示例#35
0
 public static string GetContentType(this CDO.Message message)
 {
     return(message.GetHeader(Header_ContentType));
 }