Sending email via vba code(question)

M

mjj4golf

I have a button on a form which is to send email to clients in a table.
I got some of the code idea from msdn
http://msdn2.microsoft.com/en-us/library/ms268749.aspx

The following is a snippet of it. I understand all except the Dim email As
Outlook.MailItem ...... Could someone explain? Do I need it to do the
send of the email? What's it for?

Private Sub CreateEmailItem(ByVal subjectEmail As String, _
ByVal toEmail As String, ByVal bodyEmail As String)
Dim eMail As Outlook.MailItem = Me.CreateItem _ <<<<<< ??????
(Outlook.OlItemType.olMailItem)
With eMail
.Subject = subjectEmail
.To = toEmail
.Body = bodyEmail
.Importance = Outlook.OlImportance.olImportanceLow
.Send()
End With
End Sub

Mike
 
D

Douglas J. Steele

That code is VB.Net, not VBA.

In VBA, you need to use 2 lines to accomplish the same thing:

Dim eMail As Outlook.MailItem

Set eMail = New Outlook.MailItem
 
M

mjj4golf

Thanks, I got it working!
However, when I add a recipient, Outlook puts a msg out saying that another
program is trying to access e-mail addresses stored in Outlook. Do you wan
to allow this? And a time can be specified(1,5,10 min). Then when the .Send
is done, another msg stating a program is tryiing to send email on your
behalf. Do you want to do this?
Is there anyway to get around this?

Mike
 
D

Douglas J. Steele

Questions regarding the Outlook Security prompt are asked very frequently.
The most complete answer has been provided by Outlook MVP Sue Mosher and is
as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption (http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL
 
D

Douglas J. Steele

Despite the names, Outlook Express and Outlook are two completely different
products.

The technique being used in your sample code is known as Automation. Outlook
Express does not support Automation.
 

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