yuvaratna
asked on
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.
any code would be greatly appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER
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!
can i do that with the above code!
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
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).
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
ASKER
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
have you added a reference to Outlook?
ASKER
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.
ASKER
i dont need the mail to be in the users sent folder, so i decided to go with this approach....
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
This might be a good starting point: http://www.vbdotnetheaven.com/Uploadfile/vkulkarni/MAPIcontrolToSendMail04252005015911AM/MAPIcontrolToSendMail.aspx