コード例 #1
0
        private System.String SendMailOpenSmtp(anmar.SharpWebMail.EmailServerInfo server)
        {
            System.String             message     = null;
            System.Text.Encoding      encoding    = (System.Text.Encoding)Application["sharpwebmail/send/message/charset"];
            OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
            mailMessage.Charset = encoding.HeaderName;
            mailMessage.From    = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
            System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
            foreach (System.String token in tokens)
            {
                if (anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token))
                {
                    mailMessage.To.Add(new OpenSmtp.Mail.EmailAddress(token.Trim()));
                }
            }
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if (format != null && format.Equals("html"))
            {
                mailMessage.HtmlBody = bodyStart + FCKEditor.Value + bodyEnd;
            }
            else
            {
                mailMessage.Body = FCKEditor.Value;
            }

            if (this._headers != null)
            {
                // RFC 2822 3.6.4. Identification fields
                OpenSmtp.Mail.MailHeader references = new OpenSmtp.Mail.MailHeader("References", System.String.Empty);
                if (this._headers["Message-ID"] != null)
                {
                    mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
                    references.Body = this._headers["Message-ID"];
                }
                if (this._headers["References"] != null)
                {
                    references.Body = System.String.Concat(this._headers["References"], " ", references.Body).Trim();
                }
                else if (this._headers["In-Reply-To"] != null && this._headers["In-Reply-To"].IndexOf('>') == this._headers["In-Reply-To"].LastIndexOf('>'))
                {
                    references.Body = System.String.Concat(this._headers["In-Reply-To"], " ", references.Body).Trim();
                }
                if (!references.Body.Equals(System.String.Empty))
                {
                    mailMessage.AddCustomHeader(references);
                }
            }
            mailMessage.AddCustomHeader("X-Mailer", System.String.Concat(Application["product"], " ", Application["version"]));
            this.ProcessMessageAttachments(mailMessage);
            try {
                if (log.IsDebugEnabled)
                {
                    log.Debug(System.String.Concat("Sending message. engine: opensmtp , protocol: ", server.Protocol));
                }
                OpenSmtp.Mail.Smtp SmtpMail = null;
                if (server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth))
                {
                    anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, client.UserName, client.Password, server.Port);
                }
                else
                {
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, server.Port);
                }
                SmtpMail.SendMail(mailMessage);
                SmtpMail = null;
                if (log.IsDebugEnabled)
                {
                    log.Debug("Message sent");
                }
            } catch (System.Exception e) {
                message = e.Message;
                if (log.IsErrorEnabled)
                {
                    log.Error(System.String.Concat("Error sending message. engine: opensmtp , protocol: ", server.Protocol), e);
                }
            }
            mailMessage = null;
            return(message);
        }
コード例 #2
0
ファイル: newmessage.cs プロジェクト: jspraul/pop3pipe
        private System.String SendMailOpenSmtp( anmar.SharpWebMail.EmailServerInfo server )
        {
            System.String message = null;
            OpenSmtp.Mail.MailMessage mailMessage = new OpenSmtp.Mail.MailMessage();
            mailMessage.From = new OpenSmtp.Mail.EmailAddress(this.GetFromAddress(), this.fromname.Value);
            System.String[] tokens = anmar.SharpMimeTools.ABNF.address_regex.Split(this.toemail.Value);
            foreach ( System.String token in tokens ) {
                if ( anmar.SharpMimeTools.ABNF.address_regex.IsMatch(token ) )
                    mailMessage.To.Add (new OpenSmtp.Mail.EmailAddress(token.Trim()));
            }
            mailMessage.Subject = this.subject.Value.Trim();
            System.String format = Request.Form["format"];
            if ( format!=null && format.Equals("html") ) {
                mailMessage.HtmlBody = bodyStart + FCKEditor.Value + bodyEnd;
            } else {
                mailMessage.Body = FCKEditor.Value;
            }

            if ( this._headers != null ) {
                // RFC 2822 3.6.4. Identification fields
                OpenSmtp.Mail.MailHeader references = new OpenSmtp.Mail.MailHeader("References", System.String.Empty);
                if ( this._headers["Message-ID"]!=null ) {
                    mailMessage.AddCustomHeader("In-Reply-To", this._headers["Message-ID"]);
                    references.Body = this._headers["Message-ID"];
                }
                if ( this._headers["References"]!=null ) {
                    references.Body = System.String.Concat(this._headers["References"], " ", references.Body).Trim();
                } else if ( this._headers["In-Reply-To"]!=null && this._headers["In-Reply-To"].IndexOf('>')==this._headers["In-Reply-To"].LastIndexOf('>') ) {
                    references.Body = System.String.Concat(this._headers["In-Reply-To"], " ", references.Body).Trim();
                }
                if ( !references.Body.Equals(System.String.Empty) )
                    mailMessage.AddCustomHeader(references);
            }
            mailMessage.AddCustomHeader("X-Mailer", System.String.Concat (Application["product"], " ", Application["version"]));
            this.ProcessMessageAttachments(mailMessage);
            try {
                if ( log.IsDebugEnabled) log.Error ( "Sending message" );
                OpenSmtp.Mail.Smtp SmtpMail = null;
                if ( server.Protocol.Equals(anmar.SharpWebMail.ServerProtocol.SmtpAuth) ) {
                    anmar.SharpWebMail.IEmailClient client = (anmar.SharpWebMail.IEmailClient)Session["client"];
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, client.UserName, client.Password, server.Port);
                } else
                    SmtpMail = new OpenSmtp.Mail.Smtp(server.Host, server.Port);
                SmtpMail.SendMail(mailMessage);
                SmtpMail=null;
                if ( log.IsDebugEnabled) log.Error ( "Message sent" );
            } catch (System.Exception e) {
                message = e.Message;
                if ( log.IsErrorEnabled ) log.Error ( "Error sending message", e );
            }
            mailMessage = null;
            return message;
        }