| Author: sangeethapalani 13 Sep 2007 | Member Level: Bronze | Rating:  Points: 2 |
hi
Basically there are three ways of doing this.
Using “mailto” to open the outlook Application Using the traditional SMTP Send Mail Using the Outlook Object Library to open the outlook along with an added attachment as an integral part of the application. Using Mailto Link This is a cheesy way of doing it. Pass the attributes along with the mailto <A href=”mailto:Bob@somewhere.com?Cc:Roxy@righthere.com&Subject: Using Mailto to send mails&Body:this is a test”>.
However if you want to use this in a VB.Net LinkLabel. You can do it this way Dim strURL as String strURL = “mailto:Bob@somewhere.com?Cc:Roxy@righthere.com&Subject: Using Mailto to send mails&Body:this is a test” Process.Start(strURL)
Using SMTP Send Mail Before you start coding make sure you import the related namespace Imports System.Web.Mail Here goes the code Public Function SMTPCall() Dim strTo As String Dim strFrom As String Dim strBody As String Dim strSubject As String strTo = "Bob@somewhere.com" ' Make sure you set the from address, 'some SMTP servers wouldn't send a mail without the FROM address strFrom = "Roxy@righthere.com" strBody = "Test on Sending Mail" strSubject = "Did this mail reach you yet?" SmtpMail.Send(strFrom, strTo, strSubject, strBody) End Function
Looks good, but the limitation with the above two methods is you cannot send an attachment. What if the user wants to access the outlook address book and also send the mail an attachment? Using MSOutlook Object Library Here’s a small piece of code for outlook integration with VB.Net using MS Outlook object Library. First instantiate the Outlook application object. Make sure you add the references in the Project References. Right click on the References in the Solution Explorer. Add “Microsoft Outlook 10.0 Object Library”. Public Function OutlookCall() 'Take an instance of the Outlook App Dim oOutlook As New Outlook.Application() ' Create an instance of the MailItem Dim oMailitem As Outlook.MailItem ' Create an instance of the Attachment Dim oAttach As Outlook.Attachment oMailitem = oOutlook.CreateItem(Outlook.OlItemType.olMailItem) oMailitem.To = “Bob@somewhere.com” oMailitem.Cc = “Roxy@righthere.com” oMailitem.Subject = "Email Integration with Outlook and VB.Net" 'txtFilepath is a text box that contains the path for attachment. If (txtFilepath.Text = "") Then MsgBox ("You did not attach a file") Else 'Attach the file Path to the Mail Item oMailitem.Attachments.Add(txtFilepath.Text) End If 'PING….Displays the Outlook along with the To,Cc,Subject and Attachment oMailitem.Display() End Function
There are a lot of other features you can do with this outlook object. Hope this helps.
Note: Microsoft Outlook should be the installed on the machine. Microsoft Outlook is assumed as the default mail client application. If an existing instance of outlook send item is already running, it would still create a new mail Message. this vl help u
Regards P.sangeetha
|
| Author: Vijay Kumar Naidu 13 Sep 2007 | Member Level: Gold | Rating:  Points: 2 |
Hi Sangeetha,
Your solutions are absolutely great!! You cleared my doubt.
Thank you very much.
Regards, Vijay Kumar.
|
| Author: Vijay Kumar Naidu 13 Sep 2007 | Member Level: Gold | Rating:  Points: 2 |
Hi Sangeetha,
Your solutions are absolutely great!! You cleared my doubt.
Thank you very much.
Regards, Vijay Kumar.
|