Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-12-2008
Member
 
Join Date: Dec 2008
Posts: 19
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,
Reply With Quote
  #2  
Old 26-12-2008
Member
 
Join Date: Dec 2008
Posts: 2
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("myemail@hotmail.com")
Recipent.type = RCType
.Subject = "Sending through Outlook"
.Body = "Testing outlook Mail"
.Send()
End With
OutlookMessage = Nothing
AppOutlook = Nothing
Reply With Quote
  #3  
Old 26-12-2008
Member
 
Join Date: Dec 2008
Posts: 19
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?
Reply With Quote
  #4  
Old 26-12-2008
Member
 
Join Date: Dec 2008
Posts: 2
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("myemail@hotmail.com")
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.Send()
OutlookMessage = Nothing
AppOutlook = Nothing
End Sub
End Class
Reply With Quote
  #5  
Old 26-12-2008
Member
 
Join Date: Dec 2008
Posts: 19
Re: Unable to send an Email from VB.Net

Thanks for the new code! this works properly.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Unable to send an Email from VB.Net"
Thread Thread Starter Forum Replies Last Post
Unable to send email from my Blackberry to HP ePrint Ekachakrya Portable Devices 6 27-11-2011 11:28 AM
Unable to send email with jpeg's/mp3's attachment to a Verizon phone using Opera's email client Tawannah Technology & Internet 4 23-08-2011 08:04 AM
Unable to send email from email alias via Microsoft Office 365 FrancoL Windows Software 6 10-07-2011 08:26 PM
Unable to send email in iPhone Burt/Bert Portable Devices 5 24-02-2011 11:40 AM
Unable to send pictures via email Dheran Technology & Internet 3 04-02-2009 04:28 PM


All times are GMT +5.5. The time now is 09:41 PM.