Here is a high-level overview of how the SMTP/POP3 transports work:
1. With the SmtpTransport you (user1 in the example below) send a SOAP message to another user’s (user2) mailbox using user1's relay server.
2. After the message arrives in user2's mailbox, it will be stored in user2’s mailbox like a regular piece of mail with an attachment (the attachment is a SOAP envelope) until user2’s Pop3Transport polls for this message. The Service in Port2 does not have to be running at that time as long as its mailbox is operational.
Functionally, you can think of the SMTP/POP3 transports like any other type of mail client (e.g., Outlook Express). There is no integration with other client apps.
You can share your own mailbox with these transports. These messages will appear in your mail client with subject line "@@SOAP.......". If your client email program configuration is not set to download mails locally, the Pop3Transport will poll only for these SOAP messages, process them, and delete them from your mailbox periodically.
Here is an attached sample. Although port1 sends a message to port2, both ports are configured to send and receive messages:
class TestMessageHandler : SyncMessageHandler
{
public TestMessageHandler() : base()
{
}
public override bool ProcessMessage(Message message)
{
Console.WriteLine("ProcessMessage");
return true;
}
}
Test code:
string password1 = "password1"; // for port1 user Mail Server (Exchange) Password
string alias1 = "alias1"; // for port1 user alias
string password2 = "password2"; // for port2 user Mail Server (Exchange) Password
string alias2 = "alias2"; // for port2 user alias
string exchangeServer1 = "exchangeServer1"; // mail server's host name
string domain1 = "yourcompanydomain1.com";
string exchangeServer2 = "exchangeServer2"; // mail server's host name
string domain1 = "yourcompanydomain2.com";
Uri port1Address = new Uri("soap.mail://" + alias1 + "@" + domain1); // soap.mail://alias1@yourcompanydomain1.com
Uri port2Address = new Uri("soap.mail://" + alias2 + "@" + domain2); // soap.mail://alias2@yourcompanydomain2.com
Uri port1PopAddress = new Uri("pop://" + alias1 + ":" + password1 + "@" + exchangeServer1);
Uri port2PopAddress = new Uri("pop://" + alias2 + ":" + password2 + "@" + exchangeServer2);
// Sender code starts here
Port port1 = new Port(port1Address);
// for sending messages
// you can set these from configuration as well
SmtpTransport smtpTransport1 = port1.Transports["soap.mail"] as SmtpTransport;
smtpTransport1.RelayServer = exchangeServer1;
smtpTransport1.Sender = alias1 + "@" + domain1;
// for receiving messages
// don't need if you don't want to receive any messages back
// you can set these from configuration as well
port1.TransportAddresses.Add(new Pop3TransportAddress(port1PopAddress));
port1.ReceiveChannel.Handler = new TestMessageHandler(); //don't need if you don't want to receive any messages back
port1.Open();
Message message = new Message(port2Address,"test content");
port1.CreateSendChannel(port2Address).Send(message);
Console.WriteLine("Message Sent");
Console.WriteLine("Press Enter to Continue");
Console.ReadLine();
port1.Close();
// receiver code starts here.
Port port2 = new Port(port2Address);
// for sending messages,
// don't need if you don't want to send messages back to the port1
// you can set these from configuration as well
SmtpTransport smtpTransport2 = port2.Transports["soap.mail"] as SmtpTransport;
smtpTransport2.RelayServer = exchangeServer2;
smtpTransport2.Sender = alias2 + "@" + domain2;
// for receiving messages
// don't need if you don't want to receive any messages back
// you can set these from configuration as well
port2.TransportAddresses.Add(new Pop3TransportAddress(port2PopAddress));
port2.ReceiveChannel.Handler = new TestMessageHandler();
port2.Open();
Console.WriteLine("Press Enter to Continue");
Console.ReadLine();
port2.Close();