Full Version: Set From In Outlook Email Reminder
UtterAccess Forums > Microsoft® Access > Access Forms
winterolympic
HI,
I want to use different email address, not my email address, when sending out outlook email.
When I send an email, Access automatically uses my email for "FROM", but I want to use like general , default email, for example "company@company.com".
In outlook, I know "TO", "CC", and "BCC", but not "FROM"

How can I set "FROM" address?
Please advise me.
Thanks.

MadPiet
pretty sure you can do that with CDOSYS library.
theDBguy
Hi,

It's been a while since I did something like this buy try searching on terms like the following:

SentOnBehalfOf
SendUsing
SendUsingAccount

Hope it helps...
pere_de_chipstick
Hi

You can select an account to send from by using SendUsingAccount:

Try this demo code:
CODE
Public Function fSendUsingAccount()
    
    Dim objOutlook As Object    'Outlook.Application
    Dim oAccount As Object      'Outlook.Account
    Dim oMail As Object         'Outlook.MailItem
    Dim strAccount As String
    
        strAccount = "company@company.com"
        Set objOutlook = CreateObject("Outlook.Application")
        Set oAccount = objOutlook.Session.Accounts.Item(strAccount)    
        
        Set oMail = objOutlook.CreateItem(0)
        With oMail
            .Subject = "Sent using POP3 Account"
            .Recipients.Add ("emailaddress@gmail.com")
            .Recipients.ResolveAll
             Set .SendUsingAccount = oAccount
            .Display
        End With
        
End Function


I normally use a use a setup table / form to store the account to use and strAccount = "company@company.com" is replaced by
strAccount = Nz(DLookup("OutlookAccount", "tblAdmin", "AdminID = 1"), "")

hth

PS: Remembering of course to change "company@company.com" and "emailaddress@gmail.com" as appropriate! smile.gif
winterolympic
Thanks for help!

I tried your code, then I got an error message.
"Runtime error 5"
"INvalid procedure call or argument" on
CODE
Set .SendUsingAccount = oAccount

I hover over the "oAccount", and it says "nothing".


I found out "Not using pop3" in my account.
Is this the problem?
Please help me how to fix this.
Thanks!
pere_de_chipstick
Hi

if oAccount is returning nothing, this seems to imply that oAccount hasn't been set - check the line (Set oAccount = objOutlook.Session.Accounts.Item(strAccount) )

You may need to ensure that Outlook is running before you try the code

You could also try using early binding e.g.
CODE
    Dim objOutlook As Outlook.Application
    Dim oAccount As Outlook.Account
    Dim oMail As Outlook.MailItem
    Dim strAccount As String


I'm not sure if not using a pop3 account should matter - the pop3 reference was only a convenient subject!

hth

ps have you used a valid account name for strAccount?
River59
You have to define the send from address. In this example I used 'emOutbox

emoutbox = MrSnow@yahoo.com


CODE
with olItem (with the outlook item)
olItem.SendOnBehalfOfName = emoutbox
.To = emadd
.cc = zmadd


In your case you would use with oMail
winterolympic
QUOTE
ps have you used a valid account name for strAccount?


Ah, I used fake one, like "humanResource@company.com". Sorry, it works with valid outlook email address.

So, I can add a new account in FILE tab in OUTLOOK.

I have a question.
The Access program that I have made is for other users too.
If a user logs in my access, then reminder emails will be sent automatically in login form.

I want "humanResource@company.com" address to be appeared in FROM in the outlook.
To do that, do other users have the same account name, like "humanResource@company.com"?
Otherwise, when other users open the my access, can they have errors?

pere_de_chipstick
Hi

if the user needs to use a specific account then that account must be in their copy of Outlook

I use a setup form and load the available Outlook accounts into a combo box's ('OutlookAccount' in code below) row source which allows the user to select which account is used.

CODE
    Dim objOutlook As Object    'Outlook.Application
    Dim objNamespace As Object  'Outlook.NameSpace
    Dim oAccount As Object      'Outlook.Account

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNamespace = objOutlook.GetNamespace("MAPI")

    Me.OutlookAccount.RowSource = ""
    For Each oAccount In objOutlook.Session.Accounts
        Me.OutlookAccount.AddItem oAccount.DisplayName
    Next


On start up, your app can check if a valid account has been selected and, if not, clear any invalid selection and open the setup form to allow the user to select which account is to be used.

hth
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.