Exemplo n.º 1
0
 internal SmtpConnection(SmtpTransport parent, SmtpClient client, ICredentialsByHost credentials, ISmtpAuthenticationModule[] authenticationModules)
 {
     _client                = client;
     _credentials           = credentials;
     _authenticationModules = authenticationModules;
     _parent                = parent;
     _tcpClient             = new TcpClient();
     _onCloseHandler        = new EventHandler(OnClose);
 }
Exemplo n.º 2
0
        private void Initialize()
        {
            _transport = new SmtpTransport(this);
            if (NetEventSource.IsEnabled)
            {
                NetEventSource.Associate(this, _transport);
            }
            _onSendCompletedDelegate = new SendOrPostCallback(SendCompletedWaitCallback);

            if (_host != null && _host.Length != 0)
            {
                _host = _host.Trim();
            }

            if (_port == 0)
            {
                _port = DefaultPort;
            }

            if (_targetName == null)
            {
                _targetName = "SMTPSVC/" + _host;
            }

            if (clientDomain == null)
            {
                // We use the local host name as the default client domain
                // for the client's EHLO or HELO message. This limits the
                // information about the host that we share. Additionally, the
                // FQDN is not available to us or useful to the server (internal
                // machine connecting to public server).

                // SMTP RFC's require ASCII only host names in the HELO/EHLO message.
                string     clientDomainRaw = IPGlobalProperties.GetIPGlobalProperties().HostName;
                IdnMapping mapping         = new IdnMapping();
                try
                {
                    clientDomainRaw = mapping.GetAscii(clientDomainRaw);
                }
                catch (ArgumentException) { }

                // For some inputs GetAscii may fail (bad Unicode, etc).  If that happens
                // we must strip out any non-ASCII characters.
                // If we end up with no characters left, we use the string "LocalHost".  This
                // matches Outlook behavior.
                StringBuilder sb = new StringBuilder();
                char          ch;
                for (int i = 0; i < clientDomainRaw.Length; i++)
                {
                    ch = clientDomainRaw[i];
                    if ((ushort)ch <= 0x7F)
                    {
                        sb.Append(ch);
                    }
                }
                if (sb.Length > 0)
                {
                    clientDomain = sb.ToString();
                }
                else
                {
                    clientDomain = "LocalHost";
                }
            }
        }