Sie sind auf Seite 1von 6

MS Access send email (not from outlook or

user's email)
I know this question has been asked a few times in various context, but I have not
found a clear answer. I have email implemented for an access application using
outlook, but I'd like to move away from this. One of the purposes of the email is
to email a user his/or password if he forgot it. They can select their username for
the login screen, and if they click 'forgot password' and email is sent containing
their login information (to the email address associated with the user name).
The problem with this is that the email function as is sends an email with outlook
from the user's machine. So, users would be able to 'forgot password' other
usernames and view their own outlook outbox(sent items) to see the sensitive
up vote 7
down vote

Is there a way to e-mail like php's mail function, sending mail from the server? I
would like the emails to be sent from the same email address
i.e(, instead of from the user's outlook address after a
security prompt. If this is not possible, I am open to the idea of any other
I will also add that installing any software that would have to be installed on
every potential user's machine is not feasible.
Is this possible?
ms-access vba outlook
asked Jul 20 '12 at 12:49
shareimprove this question

edited Jul 20 '12 at 12:59

Access really can't do what you want. It is a desktop database. Andrew
Barber Jul 20 '12 at 12:52
I'm open to the idea of work arounds: idea for an example workaround could
be: only send the 'forgot password' email if the outlook email for the
user('from') matches the email for the username in the database(to). Scotch
Jul 20 '12 at 12:57
I'm not really familiar with Access code, but if there's some function that
sends mail to an SMTP service then you should be able to use any SMTP
service you want instead of the user's local Outlook. David Jul 20 '12 at
users would be able to 'forgot password' other usernames and
view their own outlook outbox(sent items) to see the sensitive

sounds like a design issue that you're trying to solve by fixing

something else instead. JimmyPena Jul 22 '12 at 16:34
add a comment

4 Answers
active oldest votes
up vote 6
down vote Windows includes an object called Collaborative Data Objects or CDO. This
accepted object allows you to send emails using any SMTP server assuming that other
prerequisites are met (firewall open, ISP not blocking ports, account is configured
on the SMTP server, SMTP server allows relaying, etc).
Most of the examples I've found use late binding, which is preferred. In my testing
on XP it appeared that the correct library reference, if you prefer to use early
binding, is "Microsoft CDO for Windows 2000 Library".
It's important to know that any time you send email you will have to send it
through (or out of) some kind of email server. This means you will have to
authenticate with that email server and also usually means that you need to send
the email out using a "From" email address that exists on that very email server.
Here's some code using late binding:
' Use
' Use

cdoSendUsingPickup = 1
cdoSendUsingPort = 2
cdoAnonymous = 0
basic (clear-text) authentication.
cdoBasic = 1
NTLM authentication
cdoNTLM = 2 'NTLM

Public Sub SendEmail()

Dim imsg As Object
Dim iconf As Object
Dim flds As Object
Dim schema As String
Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields
' send one copy with SMTP server (with autentication)
schema = ""
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = ""
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = ""
flds.Item(schema & "sendpassword") = "password"
flds.Item(schema & "smtpusessl") = False
With imsg
.To = ""

.From = ""
.Subject = "Test Send"
.HTMLBody = "Test"
'.Sender = "Sender"
'.Organization = "My Company"
'.ReplyTo = ""
Set .Configuration = iconf
End With
Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub

answered Jul 20 '12 at 13:58

shareimprove this answer
"From" email address that exists on that very email server - this does not
work for me in my locale, and from my reading I understand that you must
use the server provided by your ISP. This is to prevent spam. Fionnuala Jul
20 '12 at 14:01
That just all depends on your ISP. Some only allow port 25 to be used to talk
to their own SMTP server and some do not have this limitation. Some of your
big cable providers do this but many of your smaller ISP's do not have this
limitation. For example, neither Windstream or CenturyLink have this
limitation. You can also get around this by using an alternate port (assuming
your SMTP server is exposing an alternate port) since most ISP's only impose
this limitation on port 25. As an example of this, you can probably use GMail
as your SMTP server - GMail uses 587 or 465 with SSL. HK1 Jul 20 '12 at
add a comment

vote This works for me in MS Access 2010 / Windows 7
dow sMailServer = "myISPsmtp" 'Not just any old smtp
n sMailFromAddress = "me"
sMailToAddress = "me"
Set ObjMessage = CreateObject("CDO.Message")
sToAddress = sMailToAddress
sSubject = "Subject"
sBody = "MailBody"
ObjMessage.Subject = sSubject
ObjMessage.From = sMailFromAddress
ObjMessage.To = sToAddress

' = sCCAddress
ObjMessage.TextBody = sBody
'ObjMessage.AddAttachment sMailAttachment
configuration/sendusing") = 2
configuration/smtpserver") = sMailServer
configuration/smtpserverport") = 25

More info:

answered Jul 20 '12 at 13:43
shareimprove this answer

edited Jul 20 '12 at 16:04

So would I just be setting sMailServer to my office's email server? and the
mailFromAddress to be the dummy account that I create? ('')
and sMailTo to be a userName's email address from the databasE? Scotch Jul 20
'12 at 13:47
+1 I'm too slow ^_^ but this is a great method. I shall focus on one of my concerns
instead. You should not be storing un-encrypted passwords within your database,
and definately should not be sending that information via e-mail (even if to the
correct person). Instead you need to encrypt your passwords and also offer user's the
ability to reset their password rather than just sending it out. Matt Donnan Jul 20
'12 at 13:48
I am by no means sure which mail server will work for you, I had to use the server
supplied by my ISP, apparently this is a security measure to stop spam. Fionnuala
Jul 20 '12 at 13:48
As for from, I reckon pretty nearly anything will do. Fionnuala Jul 20 '12 at 13:50
Seems like this method lets you spoof about anything on my server. Just noticed that
2 there's an addAttachment method. Could that work with just a relative path to say, an
excel sheet? Scotch Jan 22 '13 at 23:17
show 5 more comments
vote I cannot add this to the comments because I do not have enough reputation, so please
don't axe me.
vote "Seems like this method lets you spoof about anything on my server. Just noticed that
there's an addAttachment method. Could that work with just a relative path to say, an
excel sheet? "
It works for me (Access 2010, Exchange 2010):
.AddAttachment ("URL HERE")
answered Jun 10 '15 at 18:27
shareimprove this answer
add a comment
The following MS-Access VBA code works for You DO indicate
smtpusessl=true, but you do NOT specify the port, otherwise you get error 5.7.57.
Sub SMPTTest2()
Set emailObj = CreateObject("CDO.Message")
emailObj.From = ""
emailObj.To = ""
emailObj.Subject = "Test CDO"
emailObj.TextBody = "Test CDO"
'emailObj.AddAttachment "c:\windows\win.ini"
Set emailConfig = emailObj.Configuration


using") = 2
authenticate") = 1
server") = ""
'Exclude the following line
pserverport") = 587
usessl") = True
username") = ""
password") = "mypassword"
If Err.Number = 0 Then MsgBox "Done"
End Sub

answered Feb 13 at 22:27

shareimprove this answer

add a comment