Send email from access 2007 to outlook 2010 and avoid security question -
does know in access vba how send email using outlook 2010 avoid security pop up. have tried using fnsendmailsafe code error on
blnsuccessful = objoutlook.fnsendmailsafe(strto, strcc, strbcc, _ strsubject, strmessagebody, _ strattachmentpaths)
error 438 object not support property or method
any ideas???
you'll need use outlook redemption objects. use send emails through outlook 2010 access 2007 know works. here's working code. you'll need have outlook redemption objects installed work on machine. have not made of sub's arguments optional. might consider changing function , passing false boolean value if error occurs somewhere in procedure.
call subhandlesendingemail("display", "billgates@microsoft.com", "", "", "subject goes here", "my message body", "") private sub subhandlesendingemail(sdisplayorsend string, _ sto string, _ scc string, _ sbcc string, _ ssubject string, _ smsgbody string, _ satts string) 'satts expected list of files attach, delimited "|" (known pipe) const olfolderoutbox = 4 const olfolderdrafts = 16 'this section of code attempt instance of outlook object using late binding. 'if outlook closed code should open outlook. 'if outlook not installed or install corrupted, section of code should detect that. on error resume next dim ooutlookapp object set ooutlookapp = getobject(, "outlook.application") if err.number <> 0 err.clear set ooutlookapp = createobject("outlook.application") if err.number <> 0 msgbox "error: " & err.number & vbcrlf & vbcrlf & _ err.description & vbcrlf & vbcrlf & _ "apparently not have outlook installed or configured properly." err.clear set ooutlookapp = nothing exit sub end if end if dim osession object, omsg object, oattach object dim integer, sentryid string, sstoreid string on error resume next set osession = createobject("redemption.rdosession") if err.number <> 0 msgbox "please contact database administrator , give him following message:" & vbcrlf & vbcrlf & _ "there problem creating rdosession. outlook redemption objects must not installed." err.clear set osession = nothing set ooutlookapp = nothing exit sub end if osession.logon set omsg = osession.getdefaultfolder(olfolderdrafts).items.add sstoreid = osession.getdefaultfolder(olfolderdrafts).storeid sentryid = omsg.entryid 'multiple email addresses can passed email address fields 'by passing them function, separated semicolon 'if want validate email addresses make sure have '@ symbol in them , have domain name that's formatted correctly, you'll 'need before passing function or below. omsg.to = sto omsg.cc = scc omsg.bcc = sbcc omsg.subject = ssubject 'this code put attachment filenames listed in satts array 'and attach each file attachment , embed jpegs body. if satts <> "" = 0 if instr(satts, "|") = 0 satts = satts & "|" & " " 'remove doubled delimiters satts = replace(satts, "||", "|") dim aryatt() string aryatt = split(satts, "|") until = (ubound(aryatt) + 1) 'check see if filename blank before attaching if trim(aryatt(i)) <> "" 'check see if file exists before attaching if dir(aryatt(i)) <> "" set oattach = omsg.attachments.add(aryatt(i)) 'if attachment .jpg assume want embed in email if right(aryatt(i), 4) = ".jpg" oattach.fields("mimetag") = "image/jpeg" oattach.fields(&h3712001e) = "picture" & cstr(i) 'i'm assuming want pictures below optional text that's passed function smsgbody = smsgbody & "<br><br><img align=baseline border=0 hspace=0 src=cid:picture" & cstr(i) & "><br>" end if end if end if = + 1 loop end if omsg.htmlbody = smsgbody omsg.save sentryid = omsg.entryid if lcase(sdisplayorsend) = "send" omsg.send end if osession.logoff set oattach = nothing set omsg = nothing set osession = nothing if lcase(sdisplayorsend) = "display" set omsg = ooutlookapp.getnamespace("mapi").getitemfromid(sentryid, sstoreid) err.clear on error resume next omsg.display if err.number <> 0 msgbox "there problem displaying new email because there dialog box " & _ "open in outlook. please go outlook resolve problem, " & _ "then new email in drafts folder." err.clear end if set omsg = nothing end if set ooutlookapp = nothing end sub
Comments
Post a Comment