468,491 Members | 1,996 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

sending emails using vb with outlook

I found this code below to use to send emails using VB with Outlook.
However, it gives these errors.

'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and
'Outlook.ItemEvents_Event'.
Name 'olByReference' is not declared.
Name 'olMailItem' is not declared.
Name 'olTo' is not declared.

How could i edit this code to get it to work?

Any suggestions would be greatly appreciated!!

Nicole
Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem

'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")

'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Test"
'Create some body text.
.Body = "Test"

'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("mi****@imginc.com")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With

'Send the mail message.
.Send
End With

'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub
Nov 20 '05 #1
4 4287
Have you added referances to the outlook office classes, if you go to the project add referances you will see the office objects.
Nov 20 '05 #2
Imports System.Web.Mail

Dim msg As New Web.Mail.MailMessage()

SmtpMail.SmtpServer = "yourmailservernamehere"

msg.From = "fr**@from.com"

msg.To = "to@to.com"

msg.Subject = "Subject"

msg.Body = "Body"

SmtpMail.Send(msg)

"Nicole" <nm****@bellsouth.net> wrote in message
news:6D*******************@bignews2.bellsouth.net. ..
I found this code below to use to send emails using VB with Outlook.
However, it gives these errors.

'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_Event'.
Name 'olByReference' is not declared.
Name 'olMailItem' is not declared.
Name 'olTo' is not declared.

How could i edit this code to get it to work?

Any suggestions would be greatly appreciated!!

Nicole
Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem

'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")

'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Test"
'Create some body text.
.Body = "Test"

'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("mi****@imginc.com")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With

'Send the mail message.
.Send
End With

'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub

Nov 20 '05 #4
Nicole,
It sounds like you have an older version of Outlook.

If you have Outlook XP or Outlook 2003, there are PIA's that are available
that make using Outlook from .NET easier.

The following site includes a plethora of articles on using Outlook with
..NET.

http://www.microeye.com/resources/res_outlookvsnet.htm

I believe your specific problem will be addressed with the section titled
"Rebuilding the Outlook Interop Assembly" if you are not able to upgrade to
Outlook XP or Outlook 2003.

If you have Outlook XP or Outlook 2003 then I would suggest you install the
respective PIA.

Hope this helps
Jay

"Nicole" <nm****@bellsouth.net> wrote in message
news:6D*******************@bignews2.bellsouth.net. ..
I found this code below to use to send emails using VB with Outlook.
However, it gives these errors.

'Send' is ambiguous across the inherited interfaces 'Outlook._MailItem' and 'Outlook.ItemEvents_Event'.
Name 'olByReference' is not declared.
Name 'olMailItem' is not declared.
Name 'olTo' is not declared.

How could i edit this code to get it to work?

Any suggestions would be greatly appreciated!!

Nicole
Sub NewMailMessage()
Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim newMail As Outlook.MailItem

'Return a reference to the MAPI layer.
Set ns = ol.GetNamespace("MAPI")

'Create a new mail message item.
Set newMail = ol.CreateItem(olMailItem)
With newMail
'Add the subject of the mail message.
.Subject = "Test"
'Create some body text.
.Body = "Test"

'Add a recipient and test to make sure that the
'address is valid using the Resolve method.
With .Recipients.Add("mi****@imginc.com")
.Type = olTo
If Not .Resolve Then
MsgBox "Unable to resolve address.", vbInformation
Exit Sub
End If
End With

'Send the mail message.
.Send
End With

'Release memory.
Set ol = Nothing
Set ns = Nothing
Set newMail = Nothing
End Sub

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by joe215 | last post: by
2 posts views Thread by Mr. x | last post: by
5 posts views Thread by horsetransport | last post: by
6 posts views Thread by ssankar | last post: by
3 posts views Thread by gieforce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.