[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Email notification through outlook using vb.Net

Posted on 2009-02-18
13
Medium Priority
?
1,294 Views
Last Modified: 2013-11-07
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.
0
Comment
Question by:yuvaratna
  • 6
  • 4
  • 3
13 Comments
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 23671580
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
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 23671817
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
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 23671828
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23671882
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
 

Author Comment

by:yuvaratna
ID: 23671889
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23671906
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23671953
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
 
LVL 9

Expert Comment

by:Rob Siklos
ID: 23671966
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
 

Author Comment

by:yuvaratna
ID: 23675575
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23675614
have you added a reference to Outlook?
0
 

Author Comment

by:yuvaratna
ID: 23675766
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
 

Author Comment

by:yuvaratna
ID: 23675792
i dont need the mail to be in the users sent folder, so i decided to go with this approach....
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 23676507
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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question