3/4/12

Send Email Using your default Outlook Account

 
Sometimes we can face smtp problems when we want to send an email via .NET code.Proxy Problem Or not using the right SMTP port.A more esay way is to use the interoperability  between outlook and visual studio framework.
With adding the Microsoft.Office.Interop reference to our project we can send an email with our default account of outlook.

      ---> 
Under a button Click put the code snippet below :
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesButton1.Click
Dim App As New Outlook.Application()
Dim email As Outlook.MailItem = DirectCast(App.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
email.Recipients.Add(TextBox1.Text)
email.Subject = "ur Subject"
email.Body = "ur Body"
Try
DirectCast(email, Outlook.MailItem).Send()
MsgBox("Email is sent to  " & TextBox1.Text & " Successfully", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox("Error!Check That your Outlook is open", MsgBoxStyle.Critical)
End Try
End Sub
End Class
The recipient is entered in a simple textbox but you can use combobox or checkedboxlist to put multi email:



You will find the mail directly inserted in the sent mail box of your outlook default account.
You can download the code from this Link

No comments:

Post a Comment