vba - MS Access / Outlook 2010 - how to choose which account to send email from? -


i trying send emails specific account sends main no matter how code try or do. there way tell send particular account? writing code in ms access, using outlook objects.

sub testemail()     on error resume next     set outapp = getobject(, "outlook.application")      if outapp nothing         set outapp = createobject("outlook.application")     end if       set omail = outapp.createitem(olmailitem)      omail         .to = "randomaddress@randomdomain.com"         .subject = "test2"          .send     end      set outapp = nothing     set omail = nothing  end sub 

updated code:

option compare database  sub testemail()     on error resume next     set oapp = createobject("outlook.application")     set omail = oapp.createitem(olmailitem)     set olaccount = oapp.account     set olaccounttemp = oapp.account     dim foundaccount boolean     dim strfrom string     strfrom = "fromaddy@randomaddress.com"          foundaccount = false     set olaccounts = oapp.application.session.accounts     each olaccounttemp in olaccounts         debug.print olaccounttemp.smtpaddress         if (olaccounttemp.smtpaddress = strfrom)             set olaccount = olaccounttemp             foundaccount = true             exit         end if     next      if foundaccount         debug.print "acct found!"         omail             .to = "randomaddress@random.com"             .body = "message!"             .subject = "test3"             .sendusingaccount = olaccount         end     else         debug.print "no acct found"     end if      set oapp = nothing     set omail = nothing     set olaccounts = nothing     set olaccount = nothing     set olaccounttemp = nothing end sub 

try using

set omail.sendusingaccount=olaccount 

instead of

omail.sendusingaccount=olaccount 

it worked me, code perfect, set missing.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -