Unable to send an Email from VB.Net
Hi,
I want to send an email from a VB.Net 2005 application. we use Exchange Server, But then I want it to send the email without user intervention.
How can I get this to work in .Net, or is there a better way to send an email from .Net, without user intervention?
Thanks,
Re: Unable to send an Email from VB.Net
If you don't have SMTP in Exchange Server...
I am not sure, do you want to send mail through outlook?
Try this snippet
Dim AppOutlook As Object
Dim OutlookMessage As Object
Const MailItem = 0
Const RCType = 1
AppOutlook = CreateObject("Outlook.Application")
OutlookMessage = AppOutlook.CreateItem(MailItem)
With OutlookMessage
Dim Recipent As Object = .Recipients.Add("[email protected]")
Recipent.type = RCType
.Subject = "Sending through Outlook"
.Body = "Testing outlook Mail"
.Send()
End With
OutlookMessage = Nothing
AppOutlook = Nothing
Re: Unable to send an Email from VB.Net
I have looked into this carefully, and found two problems with this approach. First, I get the system exception whenever Outlook is running in background. I cannot prohibit my users from using Outlook at the same time as they use this application.
But when I am not running Outlook, I get another error at the Dim Recipient as Object line, "Operation aborted (exception from HRESULT: 0x8000400 (E_ABORT))".
so what to do for that?
Re: Unable to send an Email from VB.Net
ok i have a another way to do this, just follow the bellow steps.
1 Go to Project Add Reference and in .net tab find Microsoft.Office.Interop.Outlook and press ok
2.
Imports outlook = Microsoft.Office.Interop.Outlook
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim AppOutlook As New outlook.Application
Dim OutlookMessage As outlook.MailItem = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
AppOutlook = CreateObject("Outlook.Application")
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients
Recipents.Add("[email protected]")
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.Send()
OutlookMessage = Nothing
AppOutlook = Nothing
End Sub
End Class
Re: Unable to send an Email from VB.Net
Thanks for the new code! this works properly.