예제 #1
0
        private bool TrySendMessage(IEnumerable <string> recipients, PickerServer hub, int portNumber)
        {
            bool result;

            using (SmtpClient smtpClient = new SmtpClient(hub.FQDN, portNumber, new TestMessage.SmtpClientDebugOutput(this)))
            {
                smtpClient.AuthCredentials(CredentialCache.DefaultNetworkCredentials);
                using (MemoryStream messageMemoryStream = this.GetMessageMemoryStream())
                {
                    smtpClient.DataStream = messageMemoryStream;
                    smtpClient.From       = this.Sender.ToString();
                    smtpClient.To         = recipients.ToArray <string>();
                    try
                    {
                        smtpClient.Submit();
                    }
                    catch (Exception ex)
                    {
                        base.WriteWarning(ex.Message);
                        return(false);
                    }
                    result = true;
                }
            }
            return(result);
        }
        // Token: 0x06000175 RID: 373 RVA: 0x0000AAA4 File Offset: 0x00008CA4
        private static bool SubmitMessage(EmailMessage emailMessage, string toAddress, string fromAddress, Guid externalOrganizationId)
        {
            bool result = false;
            int  num    = 3;

            for (int i = 0; i < num; i++)
            {
                try
                {
                    using (SmtpClient smtpClient = new SmtpClient(Environment.MachineName, 25, new EHALogSearchComponent.SmtpClientDebugOutput()))
                    {
                        smtpClient.AuthCredentials(CredentialCache.DefaultNetworkCredentials);
                        smtpClient.To = new string[]
                        {
                            toAddress
                        };
                        smtpClient.From = fromAddress;
                        if (externalOrganizationId != Guid.Empty)
                        {
                            smtpClient.FromParameters.Add(new KeyValuePair <string, string>("XATTRDIRECT", "Originating"));
                            smtpClient.FromParameters.Add(new KeyValuePair <string, string>("XATTRORGID", "xorgid:" + externalOrganizationId));
                        }
                        using (MemoryStream memoryStream = new MemoryStream())
                        {
                            emailMessage.MimeDocument.WriteTo(memoryStream);
                            smtpClient.DataStream = memoryStream;
                            smtpClient.Submit();
                        }
                        result = true;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (!EHALogSearchComponent.CheckTransientSmtpFailure(ex))
                    {
                        EHALogSearchComponent.logger.LogEvent(MSExchangeTransportLogSearchEventLogConstants.Tuple_TransportSyncLogEntryProcessingFailure, DateTime.UtcNow.Hour.ToString(), new object[]
                        {
                            ex
                        });
                        break;
                    }
                    if (i + 1 < num)
                    {
                        ExTraceGlobals.ServiceTracer.TraceError <Exception>((long)EHALogSearchComponent.agentLogMonitor.GetHashCode(), "EHALogSearchComponent The confirmation message submission failed with the following exception {0}. The message submission will be retried.", ex);
                    }
                    else
                    {
                        EHALogSearchComponent.logger.LogEvent(MSExchangeTransportLogSearchEventLogConstants.Tuple_TransportSyncLogEntryProcessingFailure, DateTime.UtcNow.Hour.ToString(), new object[]
                        {
                            ex
                        });
                    }
                }
            }
            return(result);
        }
예제 #3
0
 protected virtual void SendMessage(EmailMessage msg, string recipientAddress)
 {
     if (msg == null || string.IsNullOrEmpty(recipientAddress))
     {
         return;
     }
     using (ServerPickerManager serverPickerManager = new ServerPickerManager("OwaFblHandler", ServerRole.HubTransport, ExTraceGlobals.CoreTracer))
     {
         PickerServerList pickerServerList = null;
         try
         {
             pickerServerList = serverPickerManager.GetPickerServerList();
             PickerServer pickerServer = pickerServerList.PickNextUsingRoundRobinPreferringLocal();
             string       machineName  = pickerServer.MachineName;
             using (SmtpClient smtpClient = new SmtpClient(machineName, 25, new OwaFblHandler.SmtpClientDebugOutput()))
             {
                 smtpClient.AuthCredentials(CredentialCache.DefaultNetworkCredentials);
                 smtpClient.To = new string[]
                 {
                     recipientAddress
                 };
                 using (MemoryStream memoryStream = new MemoryStream())
                 {
                     msg.MimeDocument.WriteTo(memoryStream);
                     smtpClient.DataStream = memoryStream;
                     smtpClient.Submit();
                 }
             }
         }
         finally
         {
             if (pickerServerList != null)
             {
                 pickerServerList.Release();
             }
         }
     }
 }