sending emails using vb with outlook

N

Nicole

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("(e-mail address removed)")
.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
 
G

Guest

Have you added referances to the outlook office classes, if you go to the project add referances you will see the office objects.
 
E

Ed Willis

Imports System.Web.Mail

Dim msg As New Web.Mail.MailMessage()

SmtpMail.SmtpServer = "yourmailservernamehere"

msg.From = "(e-mail address removed)"

msg.To = "(e-mail address removed)"

msg.Subject = "Subject"

msg.Body = "Body"

SmtpMail.Send(msg)
 
J

Jay B. Harlow [MVP - Outlook]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top