472,783 Members | 973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,783 software developers and data experts.

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 4513
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
0
by: ifeoma | last post by:
I have a script which sends emails through Access. It sends these emails as if it was sent through Outlook. I had no problem with this using Office 2000 but with the newer Outlook 2002 it asks if I...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
8
by: Frank | last post by:
I think I've confused myself completely here :-) I have used System.Web.Mail, but am not sure if this works with Exchange Server 5.5. I asked the client if they're email server supported SMTP, and...
5
by: horsetransport | last post by:
Hello, Below is what I "Know how to do" but it doesn't accomplish what I want I have table called sndmail fields that matter useremail and mailsent
5
by: Richard Kure | last post by:
I encountered a problem sending an email on my windows XP, which I thought was a bit weird, cause it worked for me before on windows XP. So I tried on some other computers with windows XP, and...
2
by: Jodye Roebuck | last post by:
I have a program that's been automatically generating and sending emails flawlessly. My clients workstation had an automatic Microsoft security update done on it.. and now it's bombing on this...
7
by: mlevit | last post by:
Hi, I send out emails through MS Access via SendObject. I would like to know if there is a way of getting rid of the Outlook Security Popup that comes up every time an email is about to be sent. ...
6
by: ssankar | last post by:
hi all - I have been tasked to send customized emails to a set of users based on a certain condition in my company. ( This is NOT SPAM ) I have used MIME::Lite successfully to send html...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.