What is e-mail server?
A mail server is also referred as e-mail server that handles (receives & delivers) e-mail over a network, basically over the internet.
Uses of e-mail server
In this Tech Era,in our day to day life for any statement , login verification , reports , applications and many other purpose we all are using email-ids. The e-mail functionality works due to the presence of a series of e-mail servers in between the sender and the receiver.
Examples:
- Lets say we are applying for any Examination online. Once it is applied successfully we are getting confirmation message via e-mail.
- If we are doing any e-shopping, on success/failure we are getting confirm/regret message via e-mail.
- Getting monthly banking statement via e-mail.
- Sending mail to any email-id.
In all the above cases we are using various e-mail servers to perform these operations.
How e-mail server works?
Lets say we are sending any mail to another email-id. Here when we click the send button, then the email client communicates with the SMTP* server and provide the sender's and receiver's email addresses,message body and the attachments(If available) and the work of e-mail server starts. It then processes the receiver's email address and sends the message to IMAP**/POP3*** server directly(in case of same receiver domain)/routes via series of unrelated SMTP servers(in case of different receiver domain).
Need of e-mail server set up in Application
- Lets say we have an application which collects data from the user and create the monthly statistical report and sends the report to the users via email.
- Application like e-commerce sites need to send updates on the status of the purchased products to its users via email.
- Banking applications keep track of the transactions made by the users and send them the monthly statements on their transactions via mail.
In Such cases we need to have e-mail server set up for our Application.
How to set up e-mail server in ColdFusion?
In order to perform email sending operation in ColdFusion, First we need to set up a SMTP mail server for our use. If we don't have a mail server of our own, localhost can act as a mail server and ColdFusion will act normally, but emails will not arrive at their destination due to unavailability of mail server set up in localhost.
We can use Gmail,Yahoo SMTP server setting for setting up mail server in ColdFusion.
Although we can tell ColdFusion,which server to use by adding it to the cfmail tag, here we will use ColdFusion Administrator to set up our mail server.
Mail Server Set up via ColdFusion Administrator
Steps:
1) Once we login to CF Admin page, under server setting, we have Mail menu.
If we have no mail server setting present then we can add new mail server setting and if any existing mail server setting present, it will show under this menu for changing the existing setting.2)
Using GMAIL SMTP server setting**:
- Mail server: smtp.gmail.com
- User name: Gmail email address(eg. abcdef@gmail.com)
- Password: Corresponding Gmail password
- Server Port: 465
- Enable SSL: yes
OR
Using YAHOO SMTP server setting:
- Mail server: smtp.mail.yahoo.com
- User name: Yahoo email address(eg. abcdef@yahoo.in)
- Password: Corresponding Yahoo password
- Server Port: 465
- Enable SSL: yes
3) Once these setting are done, in order to verify the setting works or not we must check the "Verify Mail Server Connection" and submit the Setting.
4) Upon successful mail server setting we will get a message stating "Server has been updated successfully" and "Connection Verification Successful".
**Alternate GMAIL SMTP server setting
4) Upon successful mail server setting we will get a message stating "Server has been updated successfully" and "Connection Verification Successful".
Sending Email once the mail server is configured
We have only to write the code with From, To addresses,Subject and Body using cfmail tag.
Code:
<!--- For sending email --->
<cfmail from="testby4@yahoo.com" subject="Test Email" to="testme43@gmail.com">
This is a Test mail
</cfmail>The above code will send mail to "testme43@gmail.com" with the mentioned Subject and Body via the mail server set up in ColdFusion Administrator.
Important Observation
When you configure the mail server in ColdFusion Administrator with GMAIL SMTP server settings, upon sending email from different "FROM" addresses in code, you can notice that the From address remains the same as mentioned in the ColdFusion Mail Server Setting,where as if the mail server setting is configured with YAHOO SMTP server setting, upon sending email from different "FROM" addresses, the From addresses are the actual FROM addresses mentioned in the code.
So before using the GMAIL SMTP server you must be aware that whether you send emails from different "FROM" addresses in code , all the emails will be fired to the receiver with a single FROM address.
- Mail server: smtp.gmail.com
- User name: Gmail email address(eg. abcdef@gmail.com)
- Password: Corresponding Gmail password
- Server Port: 587
- Enable TLS: yes