public override ThenResponse Perform(EventInfo eventInfo) { ThenResponse thenResponse = ThenResponse.Continue; string destinationHost = DestinationHost?.GetText(eventInfo.Variables) ?? eventInfo.ProxyConnection.ProxyInfo.DestinationHost; int? destinationPort = DestinationPort?.GetInt(eventInfo.Variables) ?? eventInfo.ProxyConnection.ProxyInfo.DestinationPort; if (eventInfo.Direction == Messages.DataDirection.Target) { if (!String.IsNullOrEmpty(destinationHost) && destinationPort != null && (OverrideCurrentConnection || !eventInfo.ProxyConnection.HasTargetConnection)) { if (!eventInfo.ProxyConnection.InitTargetConnection(destinationHost, destinationPort.Value)) { thenResponse = ThenResponse.BreakRules; } } } else { if (!String.IsNullOrEmpty(destinationHost) && destinationPort != null && (OverrideCurrentConnection || !eventInfo.ProxyConnection.HasOriginConnection)) { if (!eventInfo.ProxyConnection.InitOriginConnection(destinationHost, destinationPort.Value)) { thenResponse = ThenResponse.BreakRules; } } } return(thenResponse); }
public void Send() { Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPAddress addr = DestinationIP ?? Resolver.GetIPs(Resolver.GetMxRecords(DestinationHost.ToLower()).First()).First(); socket.Connect(addr, DestinationPort); if (!socket.Connected) { throw new EMailTransmissionException(0, "CONNECTION " + addr + ":" + DestinationPort); } Stream stream = new NetworkStream(socket); int code; if ((code = WaitForResultCode(stream)) != 220) { throw new EMailTransmissionException(code, "CONNECTION " + addr + ":" + DestinationPort); } stream.Write(("EHLO " + SourceHost + "\r\n").GetBytes()); if ((code = WaitForResultCode(stream)) != 250) { throw new EMailTransmissionException(code, "EHLO"); } stream.Write(("MAIL FROM:<" + SourceEMail + ">\r\n").GetBytes()); if ((code = WaitForResultCode(stream)) != 250) { throw new EMailTransmissionException(code, "MAIL"); } stream.Write(("RCPT TO:<" + DestinationEMail + ">\r\n").GetBytes()); if ((code = WaitForResultCode(stream)) != 250) { throw new EMailTransmissionException(code, "RCPT"); } stream.Write("DATA\r\n".GetBytes()); string content = GetMessage() + "\r\n.\r\n"; if ((code = WaitForResultCode(stream)) != 354) { throw new EMailTransmissionException(code, "DATA"); } stream.Write(content.GetBytes()); stream.Flush(); if ((code = WaitForResultCode(stream)) != 250) { throw new EMailTransmissionException(code, "DATA-WRITE"); } stream.Write("QUIT\r\n".GetBytes()); if ((code = WaitForResultCode(stream)) != 250) { throw new EMailTransmissionException(code, "QUIT"); } }