Пример #1
0
        internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
        {
            MultiAsyncResult multiResult = new MultiAsyncResult(conn, callback, state);
            multiResult.Enter();
            IAsyncResult writeResult = conn.BeginFlush(s_onWrite, multiResult);
            if (writeResult.CompletedSynchronously)
            {
                conn.EndFlush(writeResult);
                multiResult.Leave();
            }
            SmtpReplyReader reader = conn.Reader.GetNextReplyReader();
            multiResult.Enter();

            //this actually does a read on the stream.
            IAsyncResult result = reader.BeginReadLine(s_onReadLine, multiResult);
            if (result.CompletedSynchronously)
            {
                LineInfo info = reader.EndReadLine(result);
                if (!(multiResult.Result is Exception))
                    multiResult.Result = info;
                multiResult.Leave();
            }
            multiResult.CompleteSequence();
            return multiResult;
        }
 internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
 {
     MultiAsyncResult result = new MultiAsyncResult(conn, callback, state);
     result.Enter();
     IAsyncResult result2 = conn.BeginFlush(onWrite, result);
     if (result2.CompletedSynchronously)
     {
         conn.EndFlush(result2);
         result.Leave();
     }
     SmtpReplyReader nextReplyReader = conn.Reader.GetNextReplyReader();
     result.Enter();
     IAsyncResult result3 = nextReplyReader.BeginReadLines(onReadLines, result);
     if (result3.CompletedSynchronously)
     {
         LineInfo[] infoArray = conn.Reader.CurrentReader.EndReadLines(result3);
         if (!(result.Result is Exception))
         {
             result.Result = infoArray;
         }
         result.Leave();
     }
     result.CompleteSequence();
     return result;
 }
 private static void PrepareCommand(SmtpConnection conn)
 {
     if (conn.IsStreamOpen)
     {
         throw new InvalidOperationException(SR.GetString("SmtpDataStreamOpen"));
     }
     conn.BufferBuilder.Append(SmtpCommands.Data);
 }
 private static void PrepareCommand(SmtpConnection conn, string type, string message)
 {
     conn.BufferBuilder.Append(SmtpCommands.Auth);
     conn.BufferBuilder.Append(type);
     conn.BufferBuilder.Append((byte) 0x20);
     conn.BufferBuilder.Append(message);
     conn.BufferBuilder.Append(SmtpCommands.CRLF);
 }
 internal SendMailAsyncResult(SmtpConnection connection, string from, MailAddressCollection toCollection, string deliveryNotify, AsyncCallback callback, object state) : base(null, state, callback)
 {
     this.failedRecipientExceptions = new ArrayList();
     this.toCollection = toCollection;
     this.connection = connection;
     this.from = from;
     this.deliveryNotify = deliveryNotify;
 }
 private static void PrepareCommand(SmtpConnection conn, byte[] command, string from)
 {
     if (conn.IsStreamOpen)
     {
         throw new InvalidOperationException(SR.GetString("SmtpDataStreamOpen"));
     }
     conn.BufferBuilder.Append(command);
     conn.BufferBuilder.Append(from);
     conn.BufferBuilder.Append(SmtpCommands.CRLF);
 }
Пример #7
0
        internal IAsyncResult BeginGetConnection(ServicePoint servicePoint, ContextAwareResult outerResult, AsyncCallback callback, object state)
        {
            GlobalLog.Enter("SmtpTransport#" + ValidationHelper.HashString(this) + "::BeginConnect");
            IAsyncResult result = null;
            try{
                UpdateServicePoint(servicePoint);
                connection = new SmtpConnection(this, client, credentials, authenticationModules);
                connection.Timeout = timeout;
                if(Logging.On)Logging.Associate(Logging.Web, this, connection);
                if (EnableSsl)
                {
                    connection.EnableSsl = true;
                    connection.ClientCertificates = ClientCertificates;
                }

                result = connection.BeginGetConnection(servicePoint, outerResult, callback, state);
            }
            catch(Exception innerException){
                throw new SmtpException(SR.GetString(SR.MailHostNotFound), innerException);
            }
            GlobalLog.Leave("SmtpTransport#" + ValidationHelper.HashString(this) + "::BeginConnect [....] Completion");
            return result;
        }
Пример #8
0
            internal ConnectAndHandshakeAsyncResult(SmtpConnection connection, string host, int port, ContextAwareResult outerResult, AsyncCallback callback, object state) :
                base(null, state, callback)
            {
                _connection = connection;
                _host = host;
                _port = port;

                _outerResult = outerResult;
            }
Пример #9
0
        internal IAsyncResult BeginGetConnection(ContextAwareResult outerResult, AsyncCallback callback, object state, string host, int port)
        {
            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Enter("SmtpTransport#" + LoggingHash.HashString(this) + "::BeginConnect");
            }
            IAsyncResult result = null;
            try
            {
                _connection = new SmtpConnection(this, _client, _credentials, _authenticationModules);
                _connection.Timeout = _timeout;
                if (MailEventSource.Log.IsEnabled())
                {
                    MailEventSource.Log.Associate(this, _connection);
                }
                if (EnableSsl)
                {
                    _connection.EnableSsl = true;
                    _connection.ClientCertificates = ClientCertificates;
                }

                result = _connection.BeginGetConnection(outerResult, callback, state, host, port);
            }
            catch (Exception innerException)
            {
                throw new SmtpException(SR.MailHostNotFound, innerException);
            }

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Leave("SmtpTransport#" + LoggingHash.HashString(this) + "::BeginConnect Sync Completion");
            }
            return result;
        }
Пример #10
0
 internal static void Send(SmtpConnection conn, byte[] command, MailAddress from, bool allowUnicode)
 {
     PrepareCommand(conn, command, from, allowUnicode);
     string response;
     SmtpStatusCode statusCode = CheckCommand.Send(conn, out response);
     CheckResponse(statusCode, response);
 }
 internal ConnectAndHandshakeAsyncResult(SmtpConnection connection, string host, int port, ContextAwareResult outerResult, AsyncCallback callback, object state) : base(null, state, callback)
 {
     this.currentModule = -1;
     this.connection = connection;
     this.host = host;
     this.port = port;
     this.m_OuterResult = outerResult;
 }
Пример #12
0
 internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback?callback, object?state)
 {
     PrepareCommand(conn);
     return(CheckCommand.BeginSend(conn, callback, state));
 }
 internal static string[] Send(SmtpConnection conn, string domain)
 {
     PrepareCommand(conn, domain);
     return CheckResponse(ReadLinesCommand.Send(conn));
 }
 internal static LineInfo Send(SmtpConnection conn, string type, string message)
 {
     PrepareCommand(conn, type, message);
     return CheckResponse(ReadLinesCommand.Send(conn));
 }
 private static void PrepareCommand(SmtpConnection conn, string message)
 {
     conn.BufferBuilder.Append(message);
     conn.BufferBuilder.Append(SmtpCommands.CRLF);
 }
 internal static IAsyncResult BeginSend(SmtpConnection conn, string type, string message, AsyncCallback callback, object state)
 {
     PrepareCommand(conn, type, message);
     return ReadLinesCommand.BeginSend(conn, callback, state);
 }
Пример #17
0
 internal static SmtpStatusCode Send(SmtpConnection conn, out string response)
 {
     conn.Flush();
     SmtpReplyReader reader = conn.Reader.GetNextReplyReader();
     LineInfo info = reader.ReadLine();
     response = info.Line;
     reader.Close();
     return info.StatusCode;
 }
Пример #18
0
        private static void PrepareCommand(SmtpConnection conn, string to)
        {
            if (conn.IsStreamOpen)
            {
                throw new InvalidOperationException(SR.SmtpDataStreamOpen);
            }

            conn.BufferBuilder.Append(SmtpCommands.Recipient);
            conn.BufferBuilder.Append(to, true); // Unicode validation was done prior
            conn.BufferBuilder.Append(SmtpCommands.CRLF);
        }
 internal void GetConnection(ServicePoint servicePoint)
 {
     this.UpdateServicePoint(servicePoint);
     this.connection = new SmtpConnection(this, this.client, this.credentials, this.authenticationModules);
     this.connection.Timeout = this.timeout;
     if (Logging.On)
     {
         Logging.Associate(Logging.Web, this, this.connection);
     }
     if (this.EnableSsl)
     {
         this.connection.EnableSsl = true;
         this.connection.ClientCertificates = this.ClientCertificates;
     }
     this.connection.GetConnection(servicePoint);
 }
 internal static IAsyncResult BeginSend(SmtpConnection conn, byte[] command, string from, AsyncCallback callback, object state)
 {
     PrepareCommand(conn, command, from);
     return(CheckCommand.BeginSend(conn, callback, state));
 }
 internal static void Send(SmtpConnection conn)
 {
     string str;
     PrepareCommand(conn);
     CheckResponse(CheckCommand.Send(conn, out str), str);
 }
Пример #22
0
 internal static IAsyncResult BeginSend(SmtpConnection conn, ReadOnlySpan <byte> command, MailAddress from,
                                        bool allowUnicode, AsyncCallback?callback, object?state)
 {
     PrepareCommand(conn, command, from, allowUnicode);
     return(CheckCommand.BeginSend(conn, callback, state));
 }
 internal static IAsyncResult BeginSend(SmtpConnection conn, byte[] command, string from, AsyncCallback callback, object state)
 {
     PrepareCommand(conn, command, from);
     return CheckCommand.BeginSend(conn, callback, state);
 }
 internal static IAsyncResult BeginSend(SmtpConnection conn, string domain, AsyncCallback callback, object state)
 {
     PrepareCommand(conn, domain);
     return ReadLinesCommand.BeginSend(conn, callback, state);
 }
Пример #25
0
 internal static bool Send(SmtpConnection conn, string to, out string response)
 {
     PrepareCommand(conn, to);
     return(CheckResponse(CheckCommand.Send(conn, out response), response));
 }
 internal static IAsyncResult BeginSend(SmtpConnection conn, AsyncCallback callback, object state)
 {
     PrepareCommand(conn);
     return CheckCommand.BeginSend(conn, callback, state);
 }
 internal static bool Send(SmtpConnection conn, string to, out string response)
 {
     PrepareCommand(conn, to);
     return CheckResponse(CheckCommand.Send(conn, out response), response);
 }
 internal static void Send(SmtpConnection conn, byte[] command, string from)
 {
     string str;
     PrepareCommand(conn, command, from);
     CheckResponse(CheckCommand.Send(conn, out str), str);
 }
Пример #29
0
 internal static void EndGetConnection(IAsyncResult result)
 {
     SmtpConnection.EndGetConnection(result);
 }
Пример #30
0
        internal IAsyncResult BeginGetConnection(ContextAwareResult outerResult, AsyncCallback callback, object state, string host, int port)
        {
            if (NetEventSource.IsEnabled) NetEventSource.Enter(this);
            IAsyncResult result = null;
            try
            {
                _connection = new SmtpConnection(this, _client, _credentials, _authenticationModules);
                _connection.Timeout = _timeout;
                if (NetEventSource.IsEnabled) NetEventSource.Associate(this, _connection);
                if (EnableSsl)
                {
                    _connection.EnableSsl = true;
                    _connection.ClientCertificates = ClientCertificates;
                }

                result = _connection.BeginGetConnection(outerResult, callback, state, host, port);
            }
            catch (Exception innerException)
            {
                throw new SmtpException(SR.MailHostNotFound, innerException);
            }

            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Info(this, "Sync completion");
                NetEventSource.Exit(this);
            }
            return result;
        }
Пример #31
0
 internal static LineInfo[] Send(SmtpConnection conn)
 {
     conn.Flush();
     return(conn.Reader !.GetNextReplyReader().ReadLines());
 }
Пример #32
0
        internal void GetConnection(string host, int port)
        {
            try
            {
                _connection = new SmtpConnection(this, _client, _credentials, _authenticationModules);
                _connection.Timeout = _timeout;
                if (MailEventSource.Log.IsEnabled()) MailEventSource.Log.Associate(this, _connection);

                if (EnableSsl)
                {
                    _connection.EnableSsl = true;
                    _connection.ClientCertificates = ClientCertificates;
                }

                _connection.GetConnection(host, port);
            }
            finally { }
        }
Пример #33
0
 internal static IAsyncResult BeginSend(SmtpConnection conn, string type, string message, AsyncCallback?callback, object?state)
 {
     PrepareCommand(conn, type, message);
     return(ReadLinesCommand.BeginSend(conn, callback, state));
 }
Пример #34
0
            internal AuthenticateCallbackContext(SmtpConnection thisPtr, ISmtpAuthenticationModule module, NetworkCredential credential, string spn, ChannelBinding Token)
            {
                _thisPtr = thisPtr;
                _module = module;
                _credential = credential;
                _spn = spn;
                _token = Token;

                _result = null;
            }
Пример #35
0
 private static void PrepareCommand(SmtpConnection conn, string?message)
 {
     conn.BufferBuilder.Append(message);
     conn.BufferBuilder.Append(SmtpCommands.CRLF);
 }
Пример #36
0
 internal void GetConnection(ServicePoint servicePoint)
 {           
     try {
         Debug.Assert(servicePoint != null, "no ServicePoint provided by SmtpClient");
         // check to see if we have a different connection than last time
         UpdateServicePoint(servicePoint);
         connection = new SmtpConnection(this, client, credentials, authenticationModules);
         connection.Timeout = timeout;
         if(Logging.On)Logging.Associate(Logging.Web, this, connection);
         
         if (EnableSsl)
         {
             connection.EnableSsl = true;
             connection.ClientCertificates = ClientCertificates;
         }
         connection.GetConnection(servicePoint);
     }
     finally {
         
     }
 }
Пример #37
0
 internal static LineInfo Send(SmtpConnection conn, string?message)
 {
     PrepareCommand(conn, message);
     return(CheckResponse(ReadLinesCommand.Send(conn)));
 }
Пример #38
0
 internal SendMailAsyncResult(SmtpConnection connection, MailAddress from, MailAddressCollection toCollection, 
     bool allowUnicode, string deliveryNotify, AsyncCallback callback, object state) 
     : base(null, state, callback)
 {
     this.toCollection = toCollection;
     this.connection = connection;
     this.from = from;
     this.deliveryNotify = deliveryNotify;
     this.allowUnicode = allowUnicode;
 }
Пример #39
0
 internal static IAsyncResult BeginSend(SmtpConnection conn, string domain, AsyncCallback?callback, object?state)
 {
     PrepareCommand(conn, domain);
     return(ReadLinesCommand.BeginSend(conn, callback, state));
 }
Пример #40
0
 internal static string[] Send(SmtpConnection conn, string domain)
 {
     PrepareCommand(conn, domain);
     return(CheckResponse(ReadLinesCommand.Send(conn)));
 }
 internal IAsyncResult BeginGetConnection(ServicePoint servicePoint, ContextAwareResult outerResult, AsyncCallback callback, object state)
 {
     IAsyncResult result = null;
     try
     {
         this.UpdateServicePoint(servicePoint);
         this.connection = new SmtpConnection(this, this.client, this.credentials, this.authenticationModules);
         this.connection.Timeout = this.timeout;
         if (Logging.On)
         {
             Logging.Associate(Logging.Web, this, this.connection);
         }
         if (this.EnableSsl)
         {
             this.connection.EnableSsl = true;
             this.connection.ClientCertificates = this.ClientCertificates;
         }
         result = this.connection.BeginGetConnection(servicePoint, outerResult, callback, state);
     }
     catch (Exception exception)
     {
         throw new SmtpException(SR.GetString("MailHostNotFound"), exception);
     }
     return result;
 }