473,434 Members | 1,605 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,434 software developers and data experts.

Sending email through Access from secondary email address

15 Byte
I have an Access database that I send out emails to our customers. When the command button is selected it opens Microsoft Office and generates the emails for me to send. We have now created a general email address (like info@abccompany.com) that is shared among my team. It is possible to change the from address in Outlook for the emails generated from Access? So instead of being from my email address, they are from the general email address?

Thank you
Oct 7 '22 #1
8 20918
isladogs
456 Expert Mod 256MB
I have moved your thread from General to the Access/VBA forum which will hopefully get a more focused response.

There are several methods for sending emails from Access. Which method are you using?

For example, I use CDO to send emails and that allows me to specify the send address. Any valid email address can be used.
I have an example database illustrating this approach. See CDO EMail Tester
Oct 9 '22 #2
kjhyder
15 Byte
I am using VB code to send out the emails from Outlook with Access. Below is a bit of my code regarding the emails and attachments.

Expand|Select|Wrap|Line Numbers
  1. Do While Not rs.EOF  '
  2.         temp = rs("AGENT")
  3.         MyFileName = rs("AGENT")
  4.  
  5.         attach = mypath & MyFileName & ".pdf"
  6.         strEMail = rs![email] & ";"
  7. '
  8.         DoCmd.OpenReport "R1099", acViewReport, , "[AGENT]='" & temp & "'"
  9.         DoCmd.OutputTo acOutputReport, "", acFormatPDF, attach
  10.         DoCmd.Close acReport, "R1099"
  11.         DoEvents
  12. '
  13.           With oMail
  14.              .To = Left$(strEMail, Len(strEMail) - 1)
  15.              .Body = "With the end of 2022 approaching, we are looking to get a jump on year end 1099 preparation. Please review the attached information and let us know if any corrections are required." & vbCrLf & "Thanks," & vbCrLf & "Accounting"
  16.              .Subject = MyFileName & " Tax Information"
  17.              .Attachments.Add attach
  18.              .Display
  19.           End With
I have permissions to a shared email address with others in the office. I would like the emails I am sending to come from that email address instead of my email address.

Thanks,
Oct 12 '22 #3
zmbd
5,501 Expert Mod 4TB
Good morning kjhyder;
There is an obj.SendUsingAccount function - I've not used it myself in the Access environment; however, I have used it in the Outlook environment ( Microsoft Function: outlook.mailitem.sendusingaccount ) I'm sure there's a way to use this in the Access VBA - might have to either late-bind or add the reference to the Microsoft Outlook object library.
I'll see if I can bodge something together in a little bit - may be Monday as the code I've used is on my work-account-desktop so I don't have access (punny :) ) to it right now.

>> keep in mind however, that the original sender information is pegged to the email; thus, while it may appear that it was sent directly from the secondary account (the uninformed user will not know/see any difference), the account that is associated with the primary outlook client is still in the email headers - this is an anti-spam/malware feature and there is no easy way around this within the Outlook/Office-VBA environment.
Oct 15 '22 #4
zmbd
5,501 Expert Mod 4TB
Good morning kjhyder;
Any progress on your end using the information I provided earlier?
Mind posting any progress you've made?

I do have my code:

1) You must have the desktop client installed. The code will not work with the cloud-based-outlook web-application.
Several of my remote labs have Outlook thru our company's Office365 tenant subscription; however, they do not have the desktop Outlook application installed on their local PCs which has created an issue or two for us (seems you have to pay for more "seats" and the company doesn't want to do that right now 😢 )

2) The account you want to use must be added to the desktop client
(Link to instructions: Add an email account to Outlook ) there is simply no other way to do this unless you have the account already setup

3) I can verify that the resulting email headers have your user account information included in one of the lines; thus, while it will appear for all intents and purposes to come from the chosen account, with the replyto set for that account, anyone with the knowledge how to read the message header information can trace the email right back to your exact PC if needed... Caveat emptor
Oct 22 '22 #5
ADezii
8,834 Expert 8TB
If the General EMaIL Account (info@abccompany.com) exists in your Accounts Collection, then the following should work (basic Code):
Expand|Select|Wrap|Line Numbers
  1. Dim OutApp As Object
  2. Dim objAccount As Object
  3. Dim objMail As Object
  4. Dim intCtr As Integer
  5.  
  6. Set OutApp = CreateObject("Outlook.Application")
  7.  
  8. For intCtr = 1 To OutApp.Session.Accounts.Count
  9.   If OutApp.Session.Accounts.Item(intCtr) = "info@abccompany.com" Then
  10.     Set objAccount = OutApp.Session.Accounts.Item(intCtr)
  11.     Set objMail = OutApp.CreateItem(0)
  12.       With objMail
  13.         .Subject = "Some Subject"
  14.         .Body = "Body Text here"
  15.         .To = "someone@somewhere.com"
  16.         .SendUsingAccount objAccount
  17.           .Send
  18.       End With
  19.   End If
  20. Next
  21.  
Oct 22 '22 #6
zmbd
5,501 Expert Mod 4TB
Hello ADezii
Remarkably similar to the code I have except I look for the SMTP address directly.

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Sub SendUsing_LateBindMethod_Click()
  5.     'Use following Dim statements for Late Binding
  6.     'NOTE: Additional Const declaration
  7.     Const olMailItem As Long = 0    'For Late Binding
  8.     Const olFolderInbox As Long = 6 'For Late Binding
  9.     Const olFormatHTML As Long = 2  'For Late Binding
  10.     Dim objOutlook As Object    'Outlook.Application  '(Note dimensioned as Object)
  11.     Dim objEmail As Object      'Outlook.MailItem     '(Note dimensioned as Object)
  12.     Dim objNameSpace As Object  'Outlook.NameSpace    '(Note dimensioned as Object)
  13.     Dim objFindAccount As Object 'Outlook.Account Temporary object to find the correct account object
  14.     Dim strFromSmtpAddress As String
  15.     Dim strSubject As String
  16.     Dim strToAddress As String
  17.     Dim strBodyText As String
  18.  
  19.     On Error GoTo zErrorTrap
  20. '
  21. ' Just a place to put this information
  22.     strSubject = "My Test Message - testing sendusingaccount property"
  23.     strToAddress = "BogusToEmail@TrashMail.com"
  24.     strFromSmtpAddress = "BogusSMTPEmail@TrashMail.com"
  25.     strBodyText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
  26. '
  27. ' Late bind to the outlook application - may not work for Outlook365 - must have desktop version
  28.     Set objOutlook = GetObject(, "Outlook.Application")
  29. '
  30. ' Hook to the currently running outlook application session or create a new session
  31.     If objOutlook Is Nothing Then
  32.         Set objOutlook = CreateObject("Outlook.Application")
  33.         Set objNameSpace = objOutlook.GetNamespace("MAPI")
  34.         objNameSpace.GetDefaultFolder(olFolderInbox).Display
  35.     End If
  36. '
  37. ' Create a new mail item
  38.     Set objEmail = objOutlook.CreateItem(olMailItem)
  39. '
  40. ' Find the SMPT account in the curent session that you want to send from if not the default account
  41.   If Len(strFromSmtpAddress) > 0 Then
  42.     For Each objFindAccount In objOutlook.Session.Accounts
  43.       If objFindAccount.SmtpAddress = strFromSmtpAddress Then
  44.         Set objEmail.SendUsingAccount = objFindAccount
  45.       End If
  46.     Next
  47.   End If
  48. '
  49. ' Start the email and send (note there are alot of options here - this are the basics)
  50.     With objEmail
  51.         .To = strToAddress
  52.         .Subject = strSubject
  53.         .BodyFormat = olFormatHTML
  54.         .Body = strBodyText
  55.         '
  56.         'uncomment to show the email and allow the user to edit before sending.
  57.         .Display
  58.         '
  59.         'comment out display to send without visual
  60.         '.Send
  61.         '
  62.     End With
  63.     '
  64. 'clean up the memory
  65. zRecover:
  66.     If Not objFindAccount Is Nothing Then Set objFindAccount = Nothing
  67.     If Not objOutlook Is Nothing Then Set objOutlook = Nothing
  68.     If Not objEmail Is Nothing Then Set objOutlook = Nothing
  69.     If Not objNameSpace Is Nothing Then Set objOutlook = Nothing
  70. Exit Sub
  71. zErrorTrap:
  72. 'Stop
  73.   Select Case Err.Number
  74.     Case 429
  75.       'no current outlook object resume the code and create an object
  76.       Resume Next
  77.     Case Else
  78.     MsgBox "ErrSource: " & Err.Source & vbCrLf & "ErrNum: " & Err.Number & vbCrLf & "ErrDescription: " & vbCrLf & Err.Description
  79.   End Select
  80. Resume zRecover
  81. End Sub
  82.  
Oct 22 '22 #7
kjhyder
15 Byte
Thank you both for the assistance. I will input the code changes and test.
Oct 24 '22 #8
ylimejoy27zv
1 Bit
How do I send an email from a different email address?
Step 1: Add an address you own,online payment gateway in uae,
On your computer, open Gmail.
In the top right, click Settings. ...
Click the Accounts and import or Accounts tab.
In the "Send mail as" section, click Add another email address.
Enter your name and the address you want to send from.
Click Next Step.
Oct 26 '22 #9

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

Similar topics

2
by: Tanya | last post by:
Running a PHP mail script on Linux which has Exchange as the mail server. The script does not send mail to any internal email address but sends it to any other address outside its domain! Can...
4
by: acni | last post by:
I have the following peice of code to try and send an email to selected contacts in my form.The problem is this line: StrStore = DLookup("", "qrySelectEmail", "??????") This looks up the email...
6
by: Eduardo Rosa | last post by:
Somebody knows how I queue email using .Net? thanks a lot
2
by: Jim in Arizona | last post by:
I've made an application that is a computer problems (tickets) system. The employee goes to a web page and posts the comptuer problem they're having. Then, the IS staff goes to another webpage...
1
by: Mose | last post by:
Greetings! I am using Access '97 to track company orders. It's a pretty basic setup featuring a main table (tbl_SalesSlip) and a related table (tbl_ModelsSold). I would like to send an email that...
3
by: moondaddy | last post by:
I have some code in a web app (asp.net 2.0) and am trying to send an email to 2 different recipients. The first one works and the second one fails. the first email address is of the same domain as...
0
by: gyap88 | last post by:
I am currently using vb 2005. I have 3 columns in my database. One containing all the email address,another containing usernames, another containing password. My program has this button whereby...
6
by: Drewman626 | last post by:
Can anyone tell me how to either create a doubleclick event or a command button that will start an MS Outlook email (default client) to the ContactEmail1 control? I cannot figure out how to start...
3
by: shansivamani | last post by:
using SMTP to send email. is there any settings need to be configured apart from Host name and Port, while sending emails using SMTPClient in .Net? when i try to send mail to ids which has only...
1
by: Jose Olide | last post by:
I'm attempting to do some simple lead form logic with PHP Mailer. I need to send mail to several different email addresses conditioned by the email's subject line or if possible, several...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.