maandag 14 april 2008

Send mail with telnet over SMTP

How to test your SMTP server? Use telnet. Open up a command prompt and telnet to your smtp server: TELNET server 25, where 25 is the default SMTP port.
image
220 ...
HELO [your name, can be anything]250 ...
MAIL from: [your email address, can be anything]250 ... Sender OK
RCPT to: [destination email address]250 ...
RCPT to: [destination email address]
250 ...
DATA
[type the message body including mail headers, end with enter . enter]250 Queued mail for delivery



The bold italic lines are the lines you have to type. Note, telnet sends every character you type directly to the server, so typo's are not allowed! I also a program called TCP, that does the same as telnet but only sends data after a return, so you can use that backspace!

IIS SMTP LDAP routing, WTF

Windows 2003 Server has a SMTP server, hosted in IIS6. This SMTP server has a feature, LDAP routing.

image

The documentation for this feature is pretty minimal:

With the LDAP Routing tab, you can configure the SMTP service so that it will consult an LDAP server to resolve senders and recipients. For example, you can use Active Directory directory service as an LDAP server, and use Active Directory Users and Computers to create a group mailing list that is automatically expanded on the Simple Mail Transfer Protocol (SMTP) virtual server.

Resolve sender and recipients?? How, when, based on what attribute? And what if not resolved? And what if the user is resolved? Can it be used for SMTP authorization?

Well one thing it can do is provide AD integration, so mailing groups can be created. See this tread http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_21938977.html with the interesting title "How does LDAP Routing (for the SMTP service) work? In particular together with AD"

I someone knows some decent documentation, please let me know!

vrijdag 4 april 2008

Communicating with a PERL web service

Sometimes you have communicate with a existing web services, and there is just no documentation or WSDL. In my case the web service was written in Perl. You can take these steps to try to generate a decent proxy for the web service.

First sniff the network so you have the exact request and response.

Sample request:

POST /PERL.asmx HTTP/1.1
SOAPAction : PERLWebserviceMethods#SomeMethod
Content-Type : text/xml
Host : localhost:2353
Content-Length : 544
Connection : Keep-Alive

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SomeMethod xmlns="PERLWebserviceMethods">
<ipaddress xsi:type="xsd:string">86.87.60.177</ipaddress>
</SomeMethod>
</soap:Body>
</soap:Envelope>


Sample Response (body):


<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SomeMethodResponse xmlns="PERLWebserviceMethods">
<foo xsi:type="xsd:string">blabla</foo>
<bar xsi:type="xsd:string">1</bar>
</SomeMethodResponse>
</soap:Body>
</soap:Envelope>

Then we craft a web service mimicking the PERL web service.

[WebService(Namespace = "PERLWebserviceMethods")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class PERLWebservice : System.Web.Services.WebService
{
[WebMethod]
[SoapDocumentMethod(ResponseNamespace = "PERLWebserviceMethods",
ResponseElementName = "SomeMethodResponse",
ParameterStyle = SoapParameterStyle.Bare,
Action = "PERLWebserviceMethods#SomeMethod")]
public SomeMethodResponse SomeMethod(SomeMethod ipaddress)
{
SomeMethodResponse res = new SomeMethodResponse() { foo = "blabla", bar = "1" };
return res;
}
}

[XmlRoot("SomeMethodResponse")]
public class SomeMethodResponse
{
public string foo { get; set; }
public string bar { get; set; }
}

[XmlRoot("SomeMethod")]
public class SomeMethod
{
public string ipaddress { get; set; }
}


Now we can generate a proxy with the 'normal' tooling, generate a WSDL, and connect to the PERL web service. The trick is in using the SoapParameterStyle.Bare. This gives al lot more flexibility in crafting the resulting soap.

When this method fails you can go the WCF route and use the available hooks in WCF to consume the web services.

First post

This will be a technical blog where I will share my experiences as a .Net software developer.