473,463 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to send email from Access without using Outlook

Seth Schrock
2,965 Expert 2GB
I would like to be able to send emails from my database. Since not all of the users have Outlook, I need a method that doesn't use Outlook. I do have a VBScript that sends emails, but I don't know how to incorporate the code into my database. Here is my VBScript code if anyone is interested (with the email addresses edited)
Expand|Select|Wrap|Line Numbers
  1. Const OverwriteExisting = True
  2.  
  3. Set objFSO = CreateObject("Scripting.FileSystemObject")
  4.  
  5. objFSO.CopyFile "\\ftcbank1\databases\Loan Tracking\Installation Files\Loan Tracking.accdb" , "C:\Loan Tracking\", OverwriteExisting
  6.  
  7. WScript.Echo EMail( "Loan Tracking <user@company.com>", _
  8.             "Seth Schrock <blank@company.com>", _
  9.                     "IT Inventory has been updated.", _
  10.                     "This works" & vbCrLf & "xyz", _
  11.                     "", _
  12.                     "", _
  13.                     "Exchange", _
  14.                     25 )
  15.  
  16. Function EMail( myFrom, myTo, mySubject, myTextBody, myHTMLBody, myAttachment, mySMTPServer, mySMTPPort )
  17.  
  18.     set objNet = CreateObject("WScript.NetWork")
  19.     strUserName = objNet.UserName
  20.  
  21.     ' Standard housekeeping
  22.     Dim i, objEmail
  23.  
  24.     ' Use custom error handling
  25.     On Error Resume Next
  26.  
  27.     ' Create an e-mail message object
  28.     Set objEmail = CreateObject( "CDO.Message" )
  29.  
  30.     ' Fill in the field values
  31.     With objEmail
  32.         .From     = strUserName & "@company.com"
  33.         .To       = "Blank@company.com"
  34.         .Subject  = "Loan Tracking"
  35.         .HTMLBody = "The Loan Tracking database on " & strUserName & "'s computer has been updated"
  36.  
  37.         If mySMTPPort = "" Then
  38.             mySMTPPort = 25
  39.         End If
  40.         With .Configuration.Fields
  41.             .Item( "http://schemas.microsoft.com/cdo/configuration/sendusing"      ) = 2
  42.             .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserver"     ) = mySMTPServer
  43.             .Item( "http://schemas.microsoft.com/cdo/configuration/smtpserverport" ) = mySMTPPort
  44.             .Update
  45.         End With
  46.         ' Send the message
  47.         .Send
  48.     End With
  49.     ' Return status message
  50.     If Err Then
  51.         EMail = "ERROR " & Err.Number & ": " & Err.Description
  52.         Err.Clear
  53.     Else
  54.         EMail = "Message sent ok"
  55.     End If
  56.  
  57.     ' Release the e-mail message object
  58.     Set objEmail = Nothing
  59.     ' Restore default error handling
  60.     On Error Goto 0
  61. End Function
If there is another solution that is better, I'm willing to use it. We use MS Exchange with most users having Outlook, but our roaming users use the Outlook Web App and not the desktop application. I suppose it would be possible to link to the server directly and send an email that way, but not sure how to or how easy that would be.

I read online that the DoCmd.SendObject sends emails using the default email application. In most cases this is Outlook, but the user might not be setup in Outlook so I don't think that this would work.
Feb 26 '13 #1
6 17564
zmbd
5,501 Expert Mod 4TB
I've used the CDO method that you seem to be attempting with this code.
However, I don't use the scripting as the IT often shuts it off.
I declare the CDO object directly...
I found the method online.... too bad I didn't save the link, that's not like me, with the code for reference; however you should be able to find it too, keywords I did note were, "MS Access CDO EMAIL VBA"
Feb 26 '13 #2
Seth Schrock
2,965 Expert 2GB
I finally found a working example. Most of them were very complicated some even had references to variables that weren't declared or set. Here is the link: email using Access and VBA without MAPI and here is my implementation of it
Expand|Select|Wrap|Line Numbers
  1. Sub mtest()
  2.  
  3. Dim cdoConfig
  4. Dim msgOne
  5.  
  6. Set cdoConfig = CreateObject("CDO.Configuration")
  7. With cdoConfig.Fields
  8. .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  9. .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = 25
  10. .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "Exchange.ftc.com"
  11. .Update
  12. End With
  13.  
  14. Set msgOne = CreateObject("CDO.Message")
  15. Set msgOne.Configuration = cdoConfig
  16. msgOne.To = "name@Company.com"
  17. msgOne.From = "Database_Notification@Company.com"
  18. msgOne.Subject = "Test email"
  19. msgOne.TextBody = "It works just fine." & vbCrLf & "Line 2."
  20. msgOne.send
  21. End Sub
I will make changes so that the values can be passed to the sub instead of hard coded, but I thought this worked splendidly.

I assume that I will have to install CDO on each computer that will use this?
Feb 26 '13 #3
Rabbit
12,516 Expert Mod 8TB
CDO should be standard. At least I haven't run into one where I couldn't use CDO.
Feb 26 '13 #4
Seth Schrock
2,965 Expert 2GB
Just noticed one thing. Lines 3 & 4 don't have a data type. Should these be left as varients or is there a better type? I'm afraid I don't understand exactly what is hapening in this code.

<<Edit>> I found another website that had them declared as objects and I tried it and it works.
Feb 26 '13 #5
Seth Schrock
2,965 Expert 2GB
I cross posted with you rabbit. I found a website that said I needed to install CDO for it to work and I didn't question it, nor did I try it without it being installed on my PC. I will be sure to try it on my test PC and see if I need it when I role it out to the users.
Feb 26 '13 #6
zmbd
5,501 Expert Mod 4TB
FYI: Seth started another thread dealing with a related topic:
Verify Email Sent via CDO
Members looking into the CDO method may fine the inforamation there useful as well.
Feb 26 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AVB | last post by:
Is there any other way to write files to a directory than allowing the IUSR write access. We have a website that will be writing XML files and Label files to a directory outside of our website...
3
by: Prakash Wadhwani | last post by:
Hi !! I have been browsing around but have not been able to find a simple, lucid solution ... or maybe I'm just too confused. I know this has been asked before by many ... but pls bear with me. ...
5
by: Michal | last post by:
Hi I need to connect to Exchange 5.5 from .Net Web Application and send email using user profile. I did it two years ago on ASP but now I have to migrate it to .Net. I can not find any...
5
by: trevisc | last post by:
Good afternoon everyone. I'm currently trying to build an automated invoice system that collects dynamic data and automatically sends out invoices. In my test database I have 23 companies that...
0
by: sai14 | last post by:
Hi All, I would like to know how to send a mail without using outlook express. the code should be in C++. The "To " and "from " address should be any thing.Eg:.It can be abc@yahoo.com or...
1
by: monyrajesh | last post by:
<%@LANGUAGE="VBSCRIPT"%> <% nam=request.Form("name") mail=request.Form("email") phoneres=request.Form("res") phonembl=request.Form("mobile") adrs=request.Form("address")...
4
by: PleaseHelpMe | last post by:
Any1 can tell me how to go about sending email with attachment in vb programming code. I know SMTP is one option, but I can't seem to get it working. Any other suggestion?? Thanks in advance
1
by: sunraj | last post by:
With the Following Fields can Anybody Help me, How do I send email from ASP using SMTP Authentication <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta...
0
by: ram1927 | last post by:
Here is my platform: .net framewrok 1.1 Windows Xp Propfessional MS Office 2007. Visual Studio 2003. Window based application. I did below mentioned steps: 1. Right click on C#...
5
by: mulamootil | last post by:
Hi - Is it possible to send email attachments to an Access Database. I know that we can collect data using email messages. It would be nice if there was a way to send an email with an attachment and...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.