Пример #1
0
        public Task Dispatch(TransportOperations outgoingMessages, TransportTransaction transaction, ContextBag context)
        {
            foreach (var operation in outgoingMessages.UnicastTransportOperations)
            {
                var    serializedHeaders = HeaderSerializer.Serialize(operation.Message.Headers);
                var    transportSettings = _settings.getTransportSettings();
                var    queueIndex        = operation.Destination.IndexOf("@", StringComparison.Ordinal);
                string to;
                string subject;
                if (queueIndex > 0)
                {
                    to      = operation.Destination.Substring(queueIndex + 1);
                    subject = $"NSB-MSG-{operation.Destination.Substring(0, queueIndex)}-{operation.Message.MessageId}";
                }
                else
                {
                    to      = transportSettings.ImapUser;
                    subject = $"NSB-MSG-{operation.Destination}-{operation.Message.MessageId}";
                }

                SmtpUtils.SendMail(
                    transportSettings.SmtpServer,
                    transportSettings.SmtpServerPort,
                    transportSettings.SmtpUser,
                    transportSettings.SmtpPassword,
                    transportSettings.ImapUser,
                    to,
                    subject,
                    serializedHeaders,
                    operation.Message.Body);
            }

            return(Task.CompletedTask);
        }
Пример #2
0
        public static ImapClient GetImapClient(this SettingsHolder settingsHolder)
        {
            var settings = settingsHolder.getTransportSettings();

            // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
            var client = new ImapClient {
                ServerCertificateValidationCallback = (s, c, h, e) => true
            };

            client.Connect(settings.ImapServer, settings.ImapServerPort, SecureSocketOptions.SslOnConnect);
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            client.Authenticate(settings.ImapUser, settings.ImapPassword);

            return(client);
        }
Пример #3
0
 public override string ToTransportAddress(LogicalAddress logicalAddress)
 {
     return(string.IsNullOrEmpty(logicalAddress.Qualifier)
         ? $"{logicalAddress.EndpointInstance.Endpoint}@{_settings.getTransportSettings().ImapUser}"
         : $"{logicalAddress.EndpointInstance.Endpoint}.{logicalAddress.Qualifier}@{_settings.getTransportSettings().ImapUser}");
 }