Jump to content

Create email with array in body


Jewtus
 Share

Go to solution Solved by Jewtus,

Recommended Posts

I'm creating a script that goes to a web page, grabs the table from the webpage and sends it as an email and I feel like there has to be a better way to do this.

_IENavigate($oIE,$URL)
$oTable = _IETableGetCollection($oIE)
$iNumTables = @extended
$oMeta = _IETableGetCollection($oIE, 1) ; Extract main table
$aMeta = _IETableWriteToArray($oMeta, True)
$oMetaCount = _IETableGetCollection($oIE, 0) ; Extract main table
$aMetaCount = _IETableWriteToArray($oMetaCount, True)
$olApp = ObjCreate("Outlook.Application")
$olMailItem = 0
$objMail = $olApp.CreateItem($olMailItem)
$objMail.Save
$objMail.To =($contactemail)
$objMail.Subject = ("ThisIsATest")
For $q=0 to UBound($aMeta) -1
    $Holder= $aMeta[$q][0]&@TAB&$aMeta[$q][1]&@TAB&$aMeta[$q][2]&@TAB&$aMeta[$q][3]&@TAB&$aMeta[$q][4]
    $objMail.HTMLBody = ($Holder&@CRLF)
Next
$objMail.Display
$oOApp = 0

This script does most of what I need to, but it puts the body as just the last line in the array. I've also tried using:

Local $content
$objMail.HTMLBody = ($aMetaCount[0][1]&@CRLF)
For $q=0 to UBound($aMeta) -1
    $Holder= $aMeta[$q][0]&@TAB&$aMeta[$q][1]&@TAB&$aMeta[$q][2]&@TAB&$aMeta[$q][3]&@TAB&$aMeta[$q][4]
    $content= $content&@CRLF&$Holder
Next
$objMail.HTMLBody = ($content&@CRLF)
$objMail.Display
$oOApp = 0

But that gets rid of all the CRLF and Tabs. Does anyone know of a simpler way to write an array into an email?

Edited by Jewtus
Link to comment
Share on other sites

  • Moderators

You have the array, correct? It is just an issue with putting the entire array into the email? Have you looked at _ArrayToString?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Solution

I did try array to string, which does improve how the code looks, but it does still ditch the CRLF and Tabs... then I realized I'm using HTMLBody and not Body...

It works fine with this:

$oTable = _IETableGetCollection($oIE)
$oMeta = _IETableGetCollection($oIE, 1) ; Extract main table
$aMeta = _IETableWriteToArray($oMeta, True)
$oMetaCount = _IETableGetCollection($oIE, 0) ; Extract main table
$aMetaCount = _IETableWriteToArray($oMetaCount, True)
$content= _ArrayToString($aMeta,@TAB,0,UBound($aMeta)-1)
$olApp = ObjCreate("Outlook.Application")
$olMailItem = 0
$objMail = $olApp.CreateItem($olMailItem)
$objMail.Save
$objMail.Body = ($aMetaCount[0][1]&@CRLF&@CRLF&$content)
$objMail.Display
$oOApp = 0
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...