Receiving Emails through SMTP BC.
By vishblog on Apr 04, 2007
As soon as you see this topic you may think that using SMTP BC you can receive emails as you receive emails in your Inbox. But the case is different here. Using SMTP BC, you can receive email which is destined for your SMTP BC and process the email based on the content.
SMTP BC is Simple Mail Transfer Protocol, which means that this is a protocol defined in RFC 821 for the mail servers defining a standard way to handle the emails. It is also a protocol for communicating with SMTP Servers for email exchanges. So, In a typical scenario when an SMTP Server receives an email it may handle in the following ways:
- Check if the destination email ids in the emails are bound
to this SMTP Server. If so, store the emails in a location where the
email clients can access it.
- If the destination email ids are not bound to this email
address, but the SMTP Server knows how to route the email to the
destination, then reroute the email to the destination.
- If it cannot recognize the email id defined, return an error.
Coming back to the SMTP BC case, How is it going to receive the email? Is it going to read it from a mail box? No.
SMTP BC is implemented in such a way that it will listen in a port (default is 25) specified in the WSDL for incoming emails. That is, it has a built in SMTP Server capability to receive emails. So, what will it do receiving email? Well it just provides the email content to the consumers of the Jbi ecosystem.
As I said, an SMTP Server has to recognize the email ids mentioned in the to,cc,bcc section of an email. But how does the SMTP BC's server recognize the email ids? In a typical scenario, an SMTP Server will have a huge database of email addresses belonging to the domain. But in our case, the SMTP BC recognizes only the email ids defined in the mailto: URL of WSDL extension's smtp:server tag's location attribute.
<wsdl:port name="smtpWSDLPort" binding="tns:smtpWSDLBinding">
You want to receive an email, store it somewhere and send an acknowledgement email to the sender. You want to parse an email which is in a specified format you know and process it. Based on the subject of the email you want to organize the emails or forward it to some other email ids.
The below demo is a simple scenario where the content and subject of an email is preserved in a file.
Here are the Steps involved:
- Create a BPEL Module.
- Create a WSDL with SMTP Binding.
- Create a WSDL with File Binding.
- Create a BPEl process.
- Using BPEL Designer draw the flow of activities.
- Create a Composite Application project.
- Add the Bpel Module to the Composite Application.
- Compile and deploy the application.
- Use an email client and configure the SMTP server to the SMTP BCs
- Send an email with to address specified in the WSDL.
You should be able to see the file containg the subject and the content. Here is the demo: