Ejemplo n.º 1
0
        /// <summary>
        /// Get the minimal header set in the specified character,
        /// and using the mime encoder provided.
        /// </summary>
        private MessageHeaderCollection GetStandardHeaders(System.Text.Encoding charset, IEncoder encoder)
        {
            MessageHeaderCollection standardheaders=new MessageHeaderCollection();

            standardheaders.Add(new MessageHeader("From", _fromaddress.ToDataString()));
            standardheaders.Add(new MessageHeader("To", _toaddresses.ToDataString()));

            if (_ccaddresses.Count>0)
            {
                standardheaders.Add(new MessageHeader("Cc", _ccaddresses.ToString()));
            }
            //if (_bccaddresses.Count>0)
            //{
            //standardheaders.Add(new MessageHeader("Bcc", _bccaddresses.ToString()));
            //}

            String subject=_subject;
            if (subject==null || subject.Trim()=="")
            {
                subject=EncodeHeaderValue("Subject", ARM.GetInstance().GetString("no_subject"));
            }
            standardheaders.Add(new MessageHeader("Subject", EncodeHeaderValue("Subject", subject)));
            standardheaders.Add(new MessageHeader("Date", new RFC2822Date(DateTime.Now, TimeZone.CurrentTimeZone).ToString()));
            if (!HasBodyTextOnly())
            {
                standardheaders.Add(new MessageHeader("MIME-Version", "1.0"));
            }
            #region X-Mailer Header
            if (_xmailer!=null)
            {
                standardheaders.Add(new MessageHeader("X-Mailer", _xmailer));
            }
            else
            {
                String xmailer=Configuration.GetInstance().GetXSender();
                if (xmailer!=null)
                {
                    standardheaders.Add(new MessageHeader("X-Mailer", xmailer));
                }
                else
                {
                    standardheaders.Add(new MessageHeader("X-Mailer", "DotNetOpenMail "+VersionInfo.GetInstance().ToString()));
                }
            }
            #endregion

            String contentType=null;
            if (HasBodyTextOnly())
            {
                // ignore the mime stuff for now
            }
            else
            {
                if (HasMixedContent())
                {
                    contentType="multipart/mixed;"+SmtpProxy.ENDOFLINE+
                        "        boundary=\""+_mimeboundary.BoundaryString+"\"";
                }
                else if (HasRelatedContent())
                {
                    contentType="multipart/related;"+SmtpProxy.ENDOFLINE+
                        "        boundary=\""+_mimeboundary.BoundaryString+"\"";
                }
                else
                {
                    contentType="multipart/alternative;"+SmtpProxy.ENDOFLINE+
                        "        boundary=\""+_mimeboundary.BoundaryString+"\"";
                }

                // note: see http://www.faqs.org/rfcs/rfc2045.html , part 6.4
                //contentType+="        charset=\""+charset.BodyName+"\"";

                standardheaders.Add(new MessageHeader("Content-Type", contentType));
                //standardheaders.Add(new MessageHeader("Content-Transfer-Encoding", encoder.ContentTransferEncodingString));
            }
            return standardheaders;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get the minimal header set in the specified character,
        /// and using the mime encoder provided.
        /// </summary>
        private MessageHeaderCollection GetStandardHeaders(System.Text.Encoding charset, IEncoder encoder)
        {
            MessageHeaderCollection standardheaders = new MessageHeaderCollection();

            standardheaders.Add(new MessageHeader("From", _fromaddress.ToDataString()));
            standardheaders.Add(new MessageHeader("To", _toaddresses.ToDataString()));

            if (_ccaddresses.Count > 0)
            {
                standardheaders.Add(new MessageHeader("Cc", _ccaddresses.ToString()));
            }
            //if (_bccaddresses.Count>0)
            //{
            //standardheaders.Add(new MessageHeader("Bcc", _bccaddresses.ToString()));
            //}

            String subject = _subject;

            if (subject == null || subject.Trim() == "")
            {
                subject = EncodeHeaderValue("Subject", ARM.GetInstance().GetString("no_subject"));
            }
            standardheaders.Add(new MessageHeader("Subject", EncodeHeaderValue("Subject", subject)));
            standardheaders.Add(new MessageHeader("Date", new RFC2822Date(DateTime.Now, TimeZone.CurrentTimeZone).ToString()));
            if (!HasBodyTextOnly())
            {
                standardheaders.Add(new MessageHeader("MIME-Version", "1.0"));
            }
            #region X-Mailer Header
            if (_xmailer != null)
            {
                standardheaders.Add(new MessageHeader("X-Mailer", _xmailer));
            }
            else
            {
                String xmailer = Configuration.GetInstance().GetXSender();
                if (xmailer != null)
                {
                    standardheaders.Add(new MessageHeader("X-Mailer", xmailer));
                }
                else
                {
                    standardheaders.Add(new MessageHeader("X-Mailer", "DotNetOpenMail " + VersionInfo.GetInstance().ToString()));
                }
            }
            #endregion

            String contentType = null;
            if (HasBodyTextOnly())
            {
                // ignore the mime stuff for now
            }
            else
            {
                if (HasMixedContent())
                {
                    contentType = "multipart/mixed;" + SmtpProxy.ENDOFLINE +
                                  "        boundary=\"" + _mimeboundary.BoundaryString + "\"";
                }
                else if (HasRelatedContent())
                {
                    contentType = "multipart/related;" + SmtpProxy.ENDOFLINE +
                                  "        boundary=\"" + _mimeboundary.BoundaryString + "\"";
                }
                else
                {
                    contentType = "multipart/alternative;" + SmtpProxy.ENDOFLINE +
                                  "        boundary=\"" + _mimeboundary.BoundaryString + "\"";
                }

                // note: see http://www.faqs.org/rfcs/rfc2045.html , part 6.4
                //contentType+="        charset=\""+charset.BodyName+"\"";

                standardheaders.Add(new MessageHeader("Content-Type", contentType));
                //standardheaders.Add(new MessageHeader("Content-Transfer-Encoding", encoder.ContentTransferEncodingString));
            }
            return(standardheaders);
        }