SentOnBehalfOfName (1 Viewer)

kitty77

Registered User.
Local time
Today, 13:15
Joined
May 27, 2019
Messages
712
I'm using the following code, works fine. Where would I place .SentOnBehalfOfName = "abc@123.com"

Code:
DoCmd.SendObject _
    acSendReport, _
    "Shipment", _
    acFormatPDF, _
    [Cemail1], _
    [email1], _
    , _
    "Shipment - " & [Mdid] & " - " & [Mnotes2], _
    [Totalsnumber] & " - " & [Mtime] & Chr(10) & Chr(10) & _
    [Ccustomer] & Chr(10) & _
    [Caddress1] & Chr(10) & _
    [Ccsz] & Chr(10) & Chr(10) & _
    "Date Sent: " & [Mdatesent] & Chr(10) & _
    "Purchase Order: " & [Mpono] & Chr(10) & _
    "Shipping Method: " & [Mshipping] & Chr(10) & _
    "Tracking No: " & [Mtrack] , _
True
 
Last edited by a moderator:

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:15
Joined
Feb 28, 2001
Messages
27,192
Which mail utility are you using? Outlook? CDO? Some variant of GMail?

If Outlook,


However, I think you have to do this as an actual send from the mail utility. The DoCmd.SendObject action doesn't give you full access to the options such as the one you want. It is sort of like a "SEND (lite)" feature to send things the way you noted.
 

Isaac

Lifelong Learner
Local time
Today, 10:15
Joined
Mar 14, 2017
Messages
8,779
There may be another way to do it, too. I think there are several.

Here is one way that I successfully used a while back, for an end-user to run who always had Outlook open, but, they always had multiple accounts loaded (including a shared mailbox - and THAT was the one I wanted it to send 'from')

This may or may not be of help. I'm providing snippets only, as the whole procedure was too hard to sanitize for public view.
Be aware this code was run from within Outlook itself (in the built-in ThisOutlookSession module, because I had it "wired" to an Outlook Rule containing a Run A Script action), so you take that into account when interpreting my (for example), Application object (in your case may be a variable, being run from within Access).

Hope this helps provide an alternate route, maybe.

Code:
Dim oAccount As Outlook.Account, SendUsingAccount As Outlook.Account, blFoundSharedAccount As Boolean
Dim strAccountName As String
For Each oAccount In Application.Session.Accounts
    strAccountName = oAccount.DisplayName
    If oAccount.DisplayName = "Department Name Shared Mailbox" Then
        Set SendUsingAccount = oAccount'***********************THIS IS THE KEY #1
        blFoundSharedAccount = True 'I used this elsewhere, you may not need it
        Exit For
    End If
Next oAccount

then, later in the procedure:

Code:
  Dim newMI As MailItem
    Set newMI = Application.CreateItem(olMailItem)
    newMI.HTMLBody = strHTML
    newMI.Subject = "Some subject"
    newMI.To = "username@domain.com"
    newMI.SendUsingAccount = SendUsingAccount '****************THIS IS THE KEY #2
 

Cronk

Registered User.
Local time
Tomorrow, 03:15
Joined
Jul 4, 2013
Messages
2,772
.SentOnBehalfOfName is a property of the MailItem object in the Outlook class. You can't use it in the DoCmd.SendObject command. To use the MailItem you will need to set a reference to Outlook in the VBA editor. Search these forums for code examples.
 

kitty77

Registered User.
Local time
Today, 13:15
Joined
May 27, 2019
Messages
712
Which mail utility are you using? Outlook? CDO? Some variant of GMail?

If Outlook,


However, I think you have to do this as an actual send from the mail utility. The DoCmd.SendObject action doesn't give you full access to the options such as the one you want. It is sort of like a "SEND (lite)" feature to send things the way you noted.
I see...
 

bastanu

AWF VIP
Local time
Today, 10:15
Joined
Apr 13, 2010
Messages
1,402
As the others mentioned Docmd.SendObject does not support SendOnBehalfOfName.
Like we discussed in your earlier thread (https://www.access-programmers.co.uk/forums/threads/outlook-accounts.320966/ post #19) there is a difference between SentOnBehalfOfName vs. SendUsingAccount. You can create a custom function that would automate Outlook (many examples around this forum and \or the web) and include sSendUsingAccount (a variable defining the email address associated with the account to use) as one of the arguments. The only advantage of Docmd.SendObject (other than it is easy to use :)) is that you don't need to worry about creating and then deleting the pdf file but those actions should be fairly trivial.

Cheers,
 

ypma

Registered User.
Local time
Today, 18:15
Joined
Apr 13, 2012
Messages
643
Kitty, I posted a similar post some time ago which was solved by members of this forum. You search" How to Make Replies to Emails sent from Ms access 2019 Go to Another Address in Outlook" you should be able to view the replies I received .
Regards Ympa
 

kitty77

Registered User.
Local time
Today, 13:15
Joined
May 27, 2019
Messages
712
So, when I use the DoCmd.SendObject it does not ask me to specifiy a path.

DoCmd.SendObject _
acSendReport, _
"Shipment", _

But when I use this... .Attachments.Add "Shipment.pdf" it wants me to specify a path of the pdf?
The pdf is in my database as a report?

How do I make this work?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 12:15
Joined
Feb 28, 2001
Messages
27,192
Attachments have to be external files. You should use DoCmd.OutputTo of the report to a .PDF (which IS an option of OutPutTo) after which you can reference it for the attachment. Just remember to provide complete file paths both for the OutputTo and for the Attachment.Add, perhaps by making the path into a proper string. (And if you want to clean up after yourself, look up the VBA verb KILL filename to see how to get rid of the file once it has been sent and you don't need it any more.)
 

Isaac

Lifelong Learner
Local time
Today, 10:15
Joined
Mar 14, 2017
Messages
8,779
So, when I use the DoCmd.SendObject it does not ask me to specifiy a path.

DoCmd.SendObject _
acSendReport, _
"Shipment", _

But when I use this... .Attachments.Add "Shipment.pdf" it wants me to specify a path of the pdf?
The pdf is in my database as a report?

How do I make this work?

As you are probably realizing by now, IF you can use DoCmd.SendObject and your use of it is based on the premise that the user has Outlook, you might as well just automate Outlook, as it will give you dozens of other options/control.
IF doing so doesn't run into a bunch of nasty security prompts, which have changed SO much over the years with different Outlook versions that I can't even remember what the most recent situation is - but IIRC, it's not good. (This is why I generally stay with Office versions several years old, they work better and are usually more fully patched!) (Unless your users don't mind a prompt and it still overall adds value, which maybe it does).

Couple good reads for you, maybe

(1) Problems sending outlook emails through Access | Access World Forums (access-programmers.co.uk)
(1) Installing Outlook 2003 to avoid security prompts/allow automation | Access World Forums (access-programmers.co.uk)
 

Users who are viewing this thread

Top Bottom