Email notification through outlook using vb.Net

I am working on a windows application using vb.Net.I need to send an E-Mail to the Admin when a form is submitted and send the confirmation back to the user when that is approved.I searched online for the code...got a couple of simple codes...but they are not using outlook....

any code would be greatly appreciated.
yuvaratnaAsked:
Who is Participating?
 
Éric MoreauConnect With a Mentor Senior .Net ConsultantCommented:
why do you need to use Outlook? it is a pain to use it from an application.

You better use System.Net.Mail to send a e-mail: http://www.emoreau.com/Entries/Articles/2007/09/Using-SystemNetMail.aspx
0
 
Rob SiklosCommented:
You need to use the windows MAPI interface.  This will allow you to send mail using the default e-mail client of the computer on which your program is running.

This might be a good starting point: http://www.vbdotnetheaven.com/Uploadfile/vkulkarni/MAPIcontrolToSendMail04252005015911AM/MAPIcontrolToSendMail.aspx
0
 
Rob SiklosCommented:
emoreau: sometimes it is preferable to use outlook, since the e-mail will be sent as the actual user, and will appear in their sent mail folder.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Éric MoreauSenior .Net ConsultantCommented:
you can use the mailto protocol but then you are not allowed to add an attachement and you are limited in the lenght of the message.
0
 
yuvaratnaAuthor Commented:
I dont want the user to enter subject,EMail....i wan the to notify the administrtor that a form has been submitted by so and so person....
can i do that with the above code!
0
 
Éric MoreauSenior .Net ConsultantCommented:
you can also use Outlook Automation (http://support.microsoft.com/?kbid=313803) but you will get a warning from Outlook that an application is trying to send something
0
 
Éric MoreauSenior .Net ConsultantCommented:
you can automate the mailto protocol in an application (you can launch it automatically using Process.Start) and fill in all the arguments (to, subject, body).
0
 
Rob SiklosCommented:
If you don't care about putting the e-mail in the user's "Sent Items" folder in outlook, then emoreau is right - there's no need to use Outlook at all - just use the stuff in System.Net.Mail
0
 
yuvaratnaAuthor Commented:
i tried using this..but it throws an errortype outlook._application is not defined...
Sub Main()
        ' Create an Outlook application.
        Dim oApp As Outlook._Application
        oApp = New Outlook.Application()
 
        ' Create a new MailItem.
        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"
        oMsg.Body = "Hello World" & vbCr & vbCr
 
        ' TODO: Replace with a valid e-mail address.
        oMsg.To = "user@example.com"
 
        ' Add an attachment
        ' TODO: Replace with a valid attachment path.
        Dim sSource As String = "C:\Temp\Hello.txt"
        ' TODO: Replace with attachment name
        Dim sDisplayName As String = "Hello.txt"
 
        Dim sBodyLen As String = oMsg.Body.Length
        Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim oAttach As Outlook.Attachment
        oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)
 
        ' Send
        oMsg.Send()
 
        ' Clean up
        oApp = Nothing
        oMsg = Nothing
        oAttach = Nothing
        oAttachs = Nothing
    End Sub

Open in new window

0
 
Éric MoreauSenior .Net ConsultantCommented:
have you added a reference to Outlook?
0
 
yuvaratnaAuthor Commented:
Hi emoreau, i tried the code you gave ..which is on your website...it workd...perfect...i need to put the code in the submit buttons click event.....because i dont want the user to enter the fields...i wanted to e mail the administrator that so and so person has registered, and send cc to the users mail adress.
0
 
yuvaratnaAuthor Commented:
i dont need the mail to be in the users sent folder, so i decided to go with this approach....
0
 
Éric MoreauSenior .Net ConsultantCommented:
you don't need to have the user to enter anything if you don't want to. Just fill all the required properties like I do in the FillBaseMessage method
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.