/// <summary>
        /// Implementation of your slot.
        /// </summary>
        /// <param name="signaler">Signaler that raised the signal.</param>
        /// <param name="input">Arguments to your slot.</param>
        public async Task SignalAsync(ISignaler signaler, Node input)
        {
            // Connecting to SMTP server.
            await Utilities.Connect(input, _client, _server);

            try
            {
                // Authenticating if we're supposed to authenticate.
                await Utilities.Authenticate(input, _client, _server);

                // Iterating through each message and sending.
                foreach (var idxMsgNode in input.Children.Where(x => x.Name == "message"))
                {
                    // Creating MimeMessage, making sure we dispose any streams created in the process.
                    var message = CreateMessage(signaler, idxMsgNode);
                    using (message.Body)
                    {
                        // Sending message over existing SMTP connection.
                        await _client.SendAsync(message);
                    }
                }
            }
            finally
            {
                // Disconnecting and sending QUIT signal to SMTP server.
                await _client.DisconnectAsync(true);
            }
        }
示例#2
0
        /// <summary>
        /// Implementation of your slot.
        /// </summary>
        /// <param name="signaler">Signaler that raised the signal.</param>
        /// <param name="input">Arguments to your slot.</param>
        public async Task SignalAsync(ISignaler signaler, Node input)
        {
            // Retrieving server connection settings.
            var settings = new ConnectionSettings(
                _configuration,
                input.Children.FirstOrDefault(x => x.Name == "server"),
                "smtp");

            // Connecting and authenticating (unless username is null).
            await _client.ConnectAsync(settings.Server, settings.Port, settings.Secure);

            try
            {
                // Checking if we're supposed to authenticate
                if (settings.Username != null || settings.Password != null)
                {
                    await _client.AuthenticateAsync(settings.Username, settings.Password);
                }

                // Iterating through each message and sending.
                foreach (var idxMsgNode in input.Children.Where(x => x.Name == "message"))
                {
                    // Creating MimeMessage, making sure we dispose any streams created in the process.
                    var message = CreateMessage(signaler, idxMsgNode);
                    try
                    {
                        // Sending message over existing SMTP connection.
                        await _client.SendAsync(message);
                    }
                    finally
                    {
                        MimeCreator.DisposeEntity(message.Body);
                    }
                }
            }
            finally
            {
                // Disconnecting and sending QUIT signal to SMTP server.
                await _client.DisconnectAsync(true);
            }
        }