Ejemplo n.º 1
0
 /// <summary>
 /// Append a collection of objects to the existing collection
 /// </summary>
 /// <param name="emailaddresses">The EmailAddressCollection to append to the existing collection.</param>
 public void AddCollection(EmailAddressCollection emailaddresses)
 {
     foreach (EmailAddress emailaddress in emailaddresses)
     {
         List.Add(emailaddress);
     }
 }
 /// <summary>
 /// Append a collection of objects to the existing collection
 /// </summary>
 /// <param name="emailaddresses">The EmailAddressCollection to append to the existing collection.</param>
 public void AddCollection( EmailAddressCollection emailaddresses )
 {
     foreach (EmailAddress emailaddress in emailaddresses)
     {
         List.Add(emailaddress);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Send out the email via the smtp server given.  If
        /// the SMTP server throws an error, an SmtpException will
        /// be thrown.  All other exceptions will be MailExceptions
        /// </summary>
        /// <param name="smtpserver">The outgoing SMTP server.</param>
        /// <returns>true if sent successfully.  (note that this
        /// will not currently return false, but in the future
        /// a false value may be used)</returns>
        public bool Send(SmtpServer smtpserver)
        {
            //SmtpProxy smtpproxy=smtpserver.GetSmtpProxy();
            if (_fromaddress == null)
            {
                throw new MailException(ARM.GetInstance().GetString("error_no_from"));
            }

            EmailAddress envelopefrom = _envelopefromaddress;

            if (envelopefrom == null)
            {
                envelopefrom = _fromaddress;
            }
            EmailAddressCollection allrecipients = new EmailAddressCollection();

            allrecipients.AddCollection(_toaddresses);
            allrecipients.AddCollection(_ccaddresses);
            allrecipients.AddCollection(_bccaddresses);
            return(smtpserver.Send(this, allrecipients, envelopefrom));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send the email.
        /// </summary>
        /// <param name="emailMessage">The completed message</param>
        /// <param name="rcpttocollection">A list of email addresses which
        /// are to be used in the RCPT TO SMTP communication</param>
        /// <param name="mailfrom">An email address for the MAIL FROM 
        /// part of the SMTP protocol.</param>
        /// <exception cref="SmtpException">throws an SmtpException if there
        /// is an unexpected SMTP error number sent from the server.</exception>
        /// <exception cref="MailException">throws a MailException if there
        /// is a network problem, connection problem, or other issue.</exception>
        /// <returns></returns>
        internal bool Send(ISendableMessage emailMessage, EmailAddressCollection rcpttocollection, EmailAddress mailfrom)
        {
            //ISmtpNegotiator negotiator=_smtpserver.GetSmtpNegotiator();
            ISmtpProxy smtpproxy=GetSmtpProxy();
            //smtpproxy.CaptureSmtpConversation=CaptureSmtpConversation;
            SmtpResponse smtpResponse=smtpproxy.Open();
            try
            {
                #region Connect
                if (smtpResponse.ResponseCode!=220)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region HELO / EHLO
                if (UseEhlo())
                {
                    EhloSmtpResponse esmtpResponse=smtpproxy.Ehlo(GetHeloHost());
                    if (esmtpResponse.ResponseCode!=250)
                    {
                        // TODO: FIX THIS
                        throw new SmtpException(esmtpResponse.ResponseCode, esmtpResponse.Message);
                    }

                    // do SMTP AUTH
                    if (this._authToken!=null)
                    {

                        smtpResponse=_authToken.Negotiate(smtpproxy, esmtpResponse.GetAvailableAuthTypes());
                        if (smtpResponse.ResponseCode!=235)
                        {
                            throw smtpResponse.GetException();
                        }
                    }

                }
                else
                {

                    smtpResponse=smtpproxy.Helo(GetHeloHost());
                    if (smtpResponse.ResponseCode!=250)
                    {
                        throw smtpResponse.GetException();
                    }
                }
                #endregion

                #region MAIL FROM
                smtpResponse=smtpproxy.MailFrom(mailfrom);
                if (smtpResponse.ResponseCode!=250)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region RCPT TO

                foreach ( EmailAddress rcpttoaddress in rcpttocollection)
                {
                    smtpResponse=smtpproxy.RcptTo(rcpttoaddress);
                    if (smtpResponse.ResponseCode!=250)
                    {
                        throw smtpResponse.GetException();
                    }
                }
                #endregion

                #region DATA

                smtpResponse=smtpproxy.Data();
                if (smtpResponse.ResponseCode!=354)
                {
                    throw smtpResponse.GetException();
                }
                //smtpResponse=negotiator.WriteData();

                String message=emailMessage.ToDataString();
                if (message==null)
                {
                    throw new MailException("The message content is null");
                }
                /*
                // START Test With Domain Keys
                // (this would appear as an event callback if it works)
                MailSigner mailsigner=new MailSigner();
                bool signed = mailsigner.signMail(message);
                if (!signed)
                {
                    throw new MailException("Error creating DomainKeys signature.");
                }
                message=mailsigner.signedHeader + message;
                // END Test With Domain Keys
                */

                // Send the data
                smtpResponse=smtpproxy.WriteData(message);
                if (smtpResponse.ResponseCode!=250)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region QUIT
                // QUIT
                smtpResponse=smtpproxy.Quit();
                if (smtpResponse.ResponseCode!=221)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

            }
            finally
            {
                smtpproxy.Close();
                OnLogSmtpCompleted(this, "Connection Closed");
            }
            return true;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Send the email.
        /// </summary>
        /// <param name="emailMessage">The completed message</param>
        /// <param name="rcpttocollection">A list of email addresses which
        /// are to be used in the RCPT TO SMTP communication</param>
        /// <param name="mailfrom">An email address for the MAIL FROM
        /// part of the SMTP protocol.</param>
        /// <exception cref="SmtpException">throws an SmtpException if there
        /// is an unexpected SMTP error number sent from the server.</exception>
        /// <exception cref="MailException">throws a MailException if there
        /// is a network problem, connection problem, or other issue.</exception>
        /// <returns></returns>
        internal bool Send(ISendableMessage emailMessage, EmailAddressCollection rcpttocollection, EmailAddress mailfrom)
        {
            //ISmtpNegotiator negotiator=_smtpserver.GetSmtpNegotiator();
            ISmtpProxy smtpproxy = GetSmtpProxy();
            //smtpproxy.CaptureSmtpConversation=CaptureSmtpConversation;
            SmtpResponse smtpResponse = smtpproxy.Open();

            try
            {
                #region Connect
                if (smtpResponse.ResponseCode != 220)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region HELO / EHLO
                if (UseEhlo())
                {
                    EhloSmtpResponse esmtpResponse = smtpproxy.Ehlo(GetHeloHost());
                    if (esmtpResponse.ResponseCode != 250)
                    {
                        // TODO: FIX THIS
                        throw new SmtpException(esmtpResponse.ResponseCode, esmtpResponse.Message);
                    }

                    // do SMTP AUTH
                    if (this._authToken != null)
                    {
                        smtpResponse = _authToken.Negotiate(smtpproxy, esmtpResponse.GetAvailableAuthTypes());
                        if (smtpResponse.ResponseCode != 235)
                        {
                            throw smtpResponse.GetException();
                        }
                    }
                }
                else
                {
                    smtpResponse = smtpproxy.Helo(GetHeloHost());
                    if (smtpResponse.ResponseCode != 250)
                    {
                        throw smtpResponse.GetException();
                    }
                }
                #endregion

                #region MAIL FROM
                smtpResponse = smtpproxy.MailFrom(mailfrom);
                if (smtpResponse.ResponseCode != 250)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region RCPT TO

                foreach (EmailAddress rcpttoaddress in rcpttocollection)
                {
                    smtpResponse = smtpproxy.RcptTo(rcpttoaddress);
                    if (smtpResponse.ResponseCode != 250)
                    {
                        throw smtpResponse.GetException();
                    }
                }
                #endregion

                #region DATA

                smtpResponse = smtpproxy.Data();
                if (smtpResponse.ResponseCode != 354)
                {
                    throw smtpResponse.GetException();
                }
                //smtpResponse=negotiator.WriteData();

                String message = emailMessage.ToDataString();
                if (message == null)
                {
                    throw new MailException("The message content is null");
                }

                /*
                 * // START Test With Domain Keys
                 * // (this would appear as an event callback if it works)
                 * MailSigner mailsigner=new MailSigner();
                 * bool signed = mailsigner.signMail(message);
                 * if (!signed)
                 * {
                 *      throw new MailException("Error creating DomainKeys signature.");
                 * }
                 * message=mailsigner.signedHeader + message;
                 * // END Test With Domain Keys
                 */


                // Send the data
                smtpResponse = smtpproxy.WriteData(message);
                if (smtpResponse.ResponseCode != 250)
                {
                    throw smtpResponse.GetException();
                }
                #endregion

                #region QUIT
                // QUIT
                smtpResponse = smtpproxy.Quit();
                if (smtpResponse.ResponseCode != 221)
                {
                    throw smtpResponse.GetException();
                }
                #endregion
            }
            finally
            {
                smtpproxy.Close();
                OnLogSmtpCompleted(this, "Connection Closed");
            }
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Send out the email via the smtp server given.  If 
        /// the SMTP server throws an error, an SmtpException will
        /// be thrown.  All other exceptions will be MailExceptions
        /// </summary>
        /// <param name="smtpserver">The outgoing SMTP server.</param>
        /// <returns>true if sent successfully.  (note that this
        /// will not currently return false, but in the future
        /// a false value may be used)</returns>
        public bool Send(SmtpServer smtpserver)
        {
            //SmtpProxy smtpproxy=smtpserver.GetSmtpProxy();
            if(_fromaddress == null)
            {
                throw new MailException(ARM.GetInstance().GetString("error_no_from"));
            }

            EmailAddress envelopefrom=_envelopefromaddress;
            if (envelopefrom==null)
            {
                envelopefrom=_fromaddress;
            }
            EmailAddressCollection allrecipients=new EmailAddressCollection();
            allrecipients.AddCollection(_toaddresses);
            allrecipients.AddCollection(_ccaddresses);
            allrecipients.AddCollection(_bccaddresses);
            return smtpserver.Send(this, allrecipients, envelopefrom);
        }