예제 #1
0
        /// <summary>
        /// Send the MAIL FROM command
        /// Throw a MailException if we can't connect.
        /// </summary>
        /// <param name="mailfrom">The Envelope-From address</param>
        /// <returns>the SMTP response</returns>
        public SmtpResponse MailFrom(EmailAddress mailfrom) {
            if (!_isConnected) {
                throw new MailException("The connection is closed.");
            }
            String message = "MAIL FROM: <" + mailfrom.Email + ">" + SmtpProxy.ENDOFLINE;
            LogDebug("SENDING: " + message);

            Write(message);
            return ReadSmtpResponse();
        }
예제 #2
0
        /// <summary>
        /// Send the MAIL FROM command
        /// Throw a MailException if we can't connect.
        /// </summary>
        /// <param name="rcpttoaddress">A recipient's address</param>
        /// <returns>the SMTP response</returns>
        public SmtpResponse RcptTo(EmailAddress rcpttoaddress) {
            if (!_isConnected) {
                throw new MailException("The connection is closed.");
            }

            String message = "RCPT TO: <" + rcpttoaddress.Email + ">" + SmtpProxy.ENDOFLINE;
            LogDebug("SENDING: " + message);
            Write(message);
            return ReadSmtpResponse();
        }
예제 #3
0
		/// <summary>
		/// Find the index of the EmailAddress in the collection
		/// </summary>
		/// <param name="value">The object to find.</param>
		/// <returns>The index, from 0, or -1 if not found.</returns>
		public int IndexOf( EmailAddress value )  
		{
			return( List.IndexOf( value ) );
		}
예제 #4
0
		/// <summary>
		/// Insert an EmailAddress into the collection at the
		/// specified index.
		/// </summary>
		/// <param name="index">The index, starting at zero.</param>
		/// <param name="emailaddress">The email address to add to the collection</param>
		public void Insert( int index, EmailAddress emailaddress )  
		{
			List.Insert( index, emailaddress );
		}
예제 #5
0
		/// <summary>
		/// Remove an address, if found, from the collection.
		/// </summary>
		/// <param name="emailaddress">The EmailAddress to remove</param>
		public void Remove( EmailAddress emailaddress )  
		{
			List.Remove( emailaddress );
		}
예제 #6
0
		/// <summary>
		/// Add an object to the collection
		/// </summary>
		/// <param name="emailaddress">The EmailAddress object to add</param>
		/// <returns></returns>
		public int Add( EmailAddress emailaddress )  
		{
			return( List.Add( emailaddress ) );
		}
예제 #7
0
 /// <summary>
 /// Add a recipient who will be "Blind Carbon Copied"
 /// as a recipient of the email.  BCC addresses are
 /// not added to the email headers, but only appear
 /// during the "RCPT TO" SMTP negotiation.
 /// </summary>
 /// <param name="emailaddress">The EmailAddress object</param>		
 public void AddBccAddress(EmailAddress emailaddress) {
     _bccaddresses.Add(emailaddress);
 }
예제 #8
0
 /// <summary>
 /// Add a Cc address to the Headers.  This will also
 /// be used during the "RCPT TO" SMTP negotiation
 /// </summary>
 /// <param name="emailaddress">Email Address object of the recipient</param>
 public void AddCcAddress(EmailAddress emailaddress) {
     _ccaddresses.Add(emailaddress);
 }
예제 #9
0
 /// <summary>
 /// Add a To address to the Headers.  This will also
 /// be used during the "RCPT TO" SMTP negotiation
 /// </summary>
 /// <param name="emailaddress">Email Address object of the recipient</param>
 public void AddToAddress(EmailAddress emailaddress) {
     _toaddresses.Add(emailaddress);
 }
예제 #10
0
		/// <summary>
		/// Add a recipient to the EmailAddressCollection
		/// of recipients
		/// </summary>
		/// <param name="emailaddress"></param>
		public void AddRcptToAddress(EmailAddress emailaddress) 
		{
			_rcpttoaddresses.Add(emailaddress);
		}
예제 #11
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;
		}