473,378 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 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 4551
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.