Introduction
Using this code snippet user would be able to send an email with attachment through Outlook, Yahoo, AOL, HOTMAIL and Gmail.
Background
Already loads of information are available on internet for the same purpose. But not all the code is placed at one place. So here is my small effort to accumulate all the code at one place and that is nothing better than CodeProject. Hopefully it will be helpful for the beginners or whoever in needs of it.
Using the code
Name Space:
Below is the Block diagram for the SMTP settings i have used to send out an email from various client providers.
1. Using Outlook:
To send an email using outlook, we need to add a reference to the dynamic link library for Outlook which is called Microsoft.Office.Interop.Outlook.dll.
For the same follow the below steps
2. Click on add a reference
3. Click on .Net Tab
4. Go through the DLL and select Microsoft.Office.Interop.Outlook.dll correctly.
6. Now we need to add a reference in our class to the Outlook reference we have added to the project in our previous example.
using Outlook = Microsoft.Office.Interop.Outlook;
And finally the code would look something like this:
2. Using HOTMAIL:
To send an email using HotMail, we need to add a reference to the dynamic link library for Hotmail/Gmail/AOL/Yahoo which is called System.Net.Mail.
For the same follow the below steps:
1. Go to solution explorer of your project
2. Select add a reference
3. Click on .Net Tab
4. Go through the DLL and select System.Net.Mail.
5. When you have selected the correct reference you select the “OK” button and this reference will be added to your project under references.
6. Now we need to add a reference in our class to the Hotmail/gmail/aol/yahoo reference we have added to the project.
using System.Net.Mail;
Note: The HOTMAIL SMTP Server requires an encrypted connection (SSL) on port 25.
And finally the code would look something like this:
5. Using Gmail:
Note: The GMAIL SMTP Server requires an encrypted connection (SSL) on port 487.
Already I am using the above code snippet for my automation purpose and its working fine for me!!
Thank you!!
Feel Free to provide your comments and suggestion.
Md. Jawed.
2 comments:
Thank you! Very useful code snippet.
Hi, I'm using outlook section. I am able to send mail locally, but when I publish it in IIS its not working. Is there is any way to do it.
Post a Comment