excel vba - Email sent through VBA using Task Scheduler gets stuck in Outbox -


i have macros , task scheduler supposed to: launch excel @ specified time, update tables, create pdf documents tables , email pdf documents select individuals.

everything runs point of creating pdf document , email. however, email gets stuck in outbox folder , not send until open outlook.

anybody know causation issue?

here code sending email:

option explicit  public strfilename string  sub emailpdfasattachment() 'this macro grabs file path , stores concatenation/variable. emails file whomever specify. ' works in excel 2000, excel 2002, excel 2003, excel 2007, excel 2010, outlook 2000, outlook 2002, outlook 2003, outlook 2007, outlook 2010. ' example sends last saved version of activeworkbook object .      dim outapp object     dim outmail object     dim filepath string      'this part setting strings , objects files grab associated filepath. (e.g. filepath setting equal text plan set each report)      filepath = "\\"servernamehere"\userfolders\_autorep\da\pdfs\sealantsvs1surfacerestore\" _     & strfilename & ".pdf"      application         .enableevents = true         .screenupdating = true   '  end      'below creats actual email , opens outlook.     set outapp = createobject("outlook.application")     set outmail = outapp.createitem(0)      on error resume next    ' ******make sure set .to recipients required view it. separate email addresses semicolon (;).    ' current distribution list:    '       outmail         .to = "example@example.com"         .cc = ""         .bcc = ""         .subject = strfilename          .htmlbody = "hello all!" & "<br>" & _         "here month's report sealants vs surface restore. goes granular show results provider." & "<br>" & _          "let me know think or comments or questions have!" & "<br>" & _          vbnewline & .htmlbody          'here attached file, saves email draft, , sends file if checks out.         .attachments.add filepath         .send      end     on error goto 0     ' application    '    .enableevents = true    '   .screenupdating = true     end 'this closes out outlook application.     set outmail = nothing     set outapp = nothing  end sub  'after completes, private sub jumps macros in workbook , quits ms excel closeworkbook application. 

i have settings listed in image below tools reference library in outlook's vba settings below:

tools reference library settings

and trust settings:

e-mail security settings

macro settings:

"enable macros" selected

"apply macro security settings installed add-ins" selected

any ideas push them through outbox area instead of getting stuck? idea have program run in morning , have these emails in inbox of select individuals time come in work.

outlook, other office app, cannot run in service(such scheduler). being said, need force outlook perform sebdrecieve , wait complete. call namespace.sendandreceiive or retrieve first syncobject object namespace.syncobjects collection, call syncobject.start , wait fro syncobject.syncend event fire.