Page 2 of 2 <12
Topic Options
#207535 - 2013-07-29 04:10 PM Re: Sendmail using outlook 2010 [Re: Allen]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
ARG!! I really need a primer for this.... Let me do that and I will post results...
Is there an online class that anyone has recorded? (WISH!)

Top
#207536 - 2013-07-29 04:19 PM Re: Sendmail using outlook 2010 [Re: Karon]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4546
Loc: USA
Kixtart FAQs and HowTo's
http://www.kixtart.org/forums/ubbthreads.php?ubb=postlist&Board=5&page=1

How to use UDFs -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=81943#Post81943

Top
#207537 - 2013-07-29 05:51 PM Re: Sendmail using outlook 2010 [Re: Allen]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
There's "Fundamentals of Programming" document on my web site that might be helpful as well. In the Resources section.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207538 - 2013-07-29 06:17 PM Re: Sendmail using outlook 2010 [Re: Allen]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
I added the Dirlist UDF to the script.
Still not getting attachments or anything e-mailed. Outlook does launch. We are using Outlook 2010 on windows 7 pro 32bit

 Code:
;**** 
;**** 

;
; Docmailer.KIX
; mail reports to certain docs
;
;  Note :  Reads doctor info from docmailer2010.txt file
;

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-
;setup


$home = "\\vsscweb\reports\Doctor Reports"
;$FSO = createobject("Scripting.FileSystemObject")


$thismo = @monthno -1
IF $thismo = 0
  $month = "12"
ELSE
  IF $thismo > 9
    $month = CSTR($thismo)
  ELSE
    $month = "0" + CSTR($thismo)
  ENDIF
ENDIF
$year = IIf(@MONTHNO = 1, @YEAR -1, @YEAR)

;open log file
IF Open(2, "\\vsclinic2\mis\reports\log$month.txt",5) = 0
  $w = WriteLine( 2 , "docmailer.kix started at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
  ELSE
  BEEP
  ? "Error opening log file: [" + @ERROR + "]"
  sleep 5
  EXIT
ENDIF


;main program loop

$rc = SetOption("NoMacrosInStrings","On")
$rc = SetOption("NoVarsInStrings","On")

$Docs = Split(ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt","Docs","Names"),"#")

If UBound($docs)>=0
	$Root = CreateObject("Outlook.Application")
	For Each $Doc in $Docs
		$docemail = ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt", $doc, "Email")
		If Len($docemail)
		$MailItem = $Root.CreateItem(0)
		$MailItem.Importance = 1
; 			- 2 high importance
; 			- 1 normal importance
; 			- 0 low importance
		$MailItem.Subject = "TEST TEST TEST Reports  -  !!! DO NOT REPLY !!! - this is a test of the new system"
		$MailItem.Sender = "sccognos@@shannonhealth.org"
		$MailItem.To = $Email
		$MailItem.Body = "!!! TEST TEST TEST - DO NOT REPLY - EMAIL IS NOT MONITORED.  FOR ASSISTANCE CALL 657-5041 !!!"
		$Attachments = DirList("$home\$doc\(current month)",2)
		If UBound($Attachments)>=0
			For Each $Attachement in $Attachments
				$MailItem.Attachments.Add($Attachment)
			Next
		Endif
		$MailItem.Send
	Endif
	Next
	$Root = 0
Endif


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  DirList() - Enumerates the files in a directory into an array.                    ;;;
;;;  Written By: Jens Meyer                                                            ;;;
;;;  http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=82581    ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function DirList($dirname, optional $options)
  dim $filename, $counter, $filepath, $mask
  dim $list, $sublist, $subcounter
  $counter=-1
  $dirname=trim($dirname)
  if $dirname=''
    $dirname=@CURDIR
  endif
  if right($dirname,1)='\'
    $dirname=left($dirname,len($dirname)-1)
  endif
  if getfileattr($dirname) & 16
    $mask='*.*'
  else
    $mask=substr($dirname,instrrev($dirname,'\')+1)
    $dirname=left($dirname,len($dirname)-len($mask)-1)
  endif
  redim $list[10]
  $filename=dir($dirname+'\'+$mask)
  while $filename<>'' and @ERROR=0
    if $filename<>'.' and $filename<>'..'
      select
      case (getfileattr($dirname+'\'+$filename) & 16)
        if $options & 1
          $counter=$counter+1
          if $options & 2
            $list[$counter]=$dirname+'\'+$filename+'\'
          else
            $list[$counter]=$filename+'\'
          endif
        endif
        if ($options & 4)
          $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
          if ubound($sublist)+1
            redim preserve $list[ubound($list)+ubound($sublist)+1]
            for $subcounter=0 to ubound($sublist)
              $counter=$counter+1
              if $options & 2
                $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
              else
                $list[$counter]=$filename+'\'+$sublist[$subcounter]
              endif
            next
          endif
        endif
      case ($options & 2)
        $counter=$counter+1
        $list[$counter]=$dirname+'\'+$filename
      case 1
        $counter=$counter+1
        $list[$counter]=$filename
      endselect
      if $counter mod 10
        redim preserve $list[$counter+10]
      endif
    endif
    $filename = dir('')
  loop
  if $counter+1
    redim preserve $list[$counter]
  else
    $list=''
  endif
  if $mask<>'*.*' and ($options & 4)
    $filename=dir($dirname+'\*.*')
    while $filename<>'' and @ERROR=0
      if $filename<>'.' and $filename<>'..'
        if (getfileattr($dirname+'\'+$filename) & 16)
          $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
          if ubound($sublist)+1
            redim preserve $list[ubound($list)+ubound($sublist)+1]
            for $subcounter=0 to ubound($sublist)
              $counter=$counter+1
              if $options & 2
                $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
              else
                $list[$counter]=$filename+'\'+$sublist[$subcounter]
              endif
            next
          endif
        endif
      endif
      $filename = dir('')
    loop
  endif
  if $counter+1
    redim preserve $list[$counter]
  else
    $list=''
  endif
  $dirlist=$list
EndFunction


$ = Close (1)

$w = WriteLine( 2 , "docmailer.kix finished at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
$w = WriteLine( 2 , "   " + Chr(13) + Chr(10) )
$ = Close (2)
RETURN
  

Top
#207540 - 2013-07-29 09:17 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
I see you're using a .txt file for the information. Is the file structured in an INI format?
Top
#207541 - 2013-07-29 09:19 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
Example of the txt file:

[Docs]
names=BOB#GEORGE#SAM

[BOB]
email=bob.jones@@suddenlink.net
[GEORGE]
email=george.hamm@@gmail.com
[SAM]
email=sam.black@@hotmail.com


Edited by Karon (2013-07-29 09:20 PM)
Edit Reason: remove last # in names

Top
#207542 - 2013-07-29 09:26 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Also this line will fail, with the NoVarsInStrings turned on.
 Code:
$Attachments = DirList("$home\$doc\(current month)",2)

Change it to...
 Code:
$Attachments = DirList($home+"\"+$doc+"\(current month)",2)

Top
#207543 - 2013-07-29 09:28 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Also the double @@'s will fail with the NoMacrosInStrings turned on.

Change the file to...
[Docs]
names=BOB#GEORGE#SAM

[BOB]
email=bob.jones@suddenlink.net
[GEORGE]
email=george.hamm@gmail.com
[SAM]
email=sam.black@hotmail.com

Also the .Sender to...
 Code:
$MailItem.Sender = "sccognos@shannonhealth.org"

Top
#207544 - 2013-07-29 09:58 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
Fixed $attachments

 Code:
$Attachments = DirList($home+"\"+$doc+"\(current month)",2)


Fixed @@ to @ in txt file and .Sender.
 Code:
$MailItem.Sender = "sccognos@shannonhealth.org"


Still nothing being created in outlook. <SIGH>

Top
#207547 - 2013-07-29 11:01 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Don't notice anything else off the top of my head. Added a few lines to help debug the problem. Try this and see if anything looks out of place when you run it.

 Code:
;**** 
;**** 
;
; Docmailer.KIX
; mail reports to certain docs
;
;  Note :  Reads doctor info from docmailer2010.txt file
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-
;setup


$home = "\\vsscweb\reports\Doctor Reports"
;$FSO = createobject("Scripting.FileSystemObject")

$month = @monthno-1

IF $month = 0
  $month = "12"
ENDIF
$month = IIf(Len($month)=1,"0"+$month,$month)
$year = IIf($month = 12, @YEAR-1, @YEAR)


;open log file
IF Open(2, "\\vsclinic2\mis\reports\log$month.txt",5) = 0
	$w = WriteLine( 2 , "docmailer.kix started at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
ELSE
	BEEP
	? "Error opening log file: [" + @ERROR + "]"
	sleep 5
	EXIT
ENDIF

;main program loop

$rc = SetOption("NoMacrosInStrings","On")
$rc = SetOption("NoVarsInStrings","On")

$Docs = Split(ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt","Docs","Names"),"#")
? "Elements in Docs Array: "+UBound($docs)

If UBound($docs)>=0
	$Root = CreateObject("Outlook.Application")
? "Outlook Creation: "+@Error
	For Each $Doc in $Docs
? "Doc: "+$Doc
		$docemail = ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt", $doc, "Email")
? "Email: "+$docemail
		If Len($docemail)
			$MailItem = $Root.CreateItem(0)
? "Root Creation: "+@Error
			$MailItem.Importance = 1
			$MailItem.Subject = "TEST TEST TEST Reports  -  !!! DO NOT REPLY !!! - this is a test of the new system"
			$MailItem.Sender = "sccognos@shannonhealth.org"
			$MailItem.To = $Email
			$MailItem.Body = "!!! TEST TEST TEST - DO NOT REPLY - EMAIL IS NOT MONITORED.  FOR ASSISTANCE CALL 657-5041 !!!"
			$Attachments = DirList($home+"\"+$doc+"\(current month)",2)
? "Elements in Attachment Array: "+UBound($attachments)
			If UBound($Attachments)>=0
				For Each $Attachement in $Attachments
					$MailItem.Attachments.Add($Attachment)
? "Attachment: "+@Error
				Next
			Endif
			$MailItem.Send
? "Send: "+@Error
		Endif
	Next
	$Root = 0
Endif

$ = Close (1)

$w = WriteLine( 2 , "docmailer.kix finished at " +@DATE + " - " + @TIME + Chr(13) + Chr(10) )
$w = WriteLine( 2 , "   " + Chr(13) + Chr(10) )
$ = Close (2)
? "Press Any Key To Exit"
get $
RETURN

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;  DirList() - Enumerates the files in a directory into an array.                    ;;;
;;;  Written By: Jens Meyer                                                            ;;;
;;;  http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Board=7&Number=82581    ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Function DirList($dirname, optional $options)
  dim $filename, $counter, $filepath, $mask
  dim $list, $sublist, $subcounter
  $counter=-1
  $dirname=trim($dirname)
  if $dirname=''
    $dirname=@CURDIR
  endif
  if right($dirname,1)='\'
    $dirname=left($dirname,len($dirname)-1)
  endif
  if getfileattr($dirname) & 16
    $mask='*.*'
  else
    $mask=substr($dirname,instrrev($dirname,'\')+1)
    $dirname=left($dirname,len($dirname)-len($mask)-1)
  endif
  redim $list[10]
  $filename=dir($dirname+'\'+$mask)
  while $filename<>'' and @ERROR=0
    if $filename<>'.' and $filename<>'..'
      select
      case (getfileattr($dirname+'\'+$filename) & 16)
        if $options & 1
          $counter=$counter+1
          if $options & 2
            $list[$counter]=$dirname+'\'+$filename+'\'
          else
            $list[$counter]=$filename+'\'
          endif
        endif
        if ($options & 4)
          $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,$options)
          if ubound($sublist)+1
            redim preserve $list[ubound($list)+ubound($sublist)+1]
            for $subcounter=0 to ubound($sublist)
              $counter=$counter+1
              if $options & 2
                $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
              else
                $list[$counter]=$filename+'\'+$sublist[$subcounter]
              endif
            next
          endif
        endif
      case ($options & 2)
        $counter=$counter+1
        $list[$counter]=$dirname+'\'+$filename
      case 1
        $counter=$counter+1
        $list[$counter]=$filename
      endselect
      if $counter mod 10
        redim preserve $list[$counter+10]
      endif
    endif
    $filename = dir('')
  loop
  if $counter+1
    redim preserve $list[$counter]
  else
    $list=''
  endif
  if $mask<>'*.*' and ($options & 4)
    $filename=dir($dirname+'\*.*')
    while $filename<>'' and @ERROR=0
      if $filename<>'.' and $filename<>'..'
        if (getfileattr($dirname+'\'+$filename) & 16)
          $sublist=dirlist($dirname+'\'+$filename+'\'+$mask,4)
          if ubound($sublist)+1
            redim preserve $list[ubound($list)+ubound($sublist)+1]
            for $subcounter=0 to ubound($sublist)
              $counter=$counter+1
              if $options & 2
                $list[$counter]=$dirname+'\'+$filename+'\'+$sublist[$subcounter]
              else
                $list[$counter]=$filename+'\'+$sublist[$subcounter]
              endif
            next
          endif
        endif
      endif
      $filename = dir('')
    loop
  endif
  if $counter+1
    redim preserve $list[$counter]
  else
    $list=''
  endif
  $dirlist=$list
EndFunction

Top
#207548 - 2013-07-30 12:09 AM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
I found a typo -
Fixed and will re-run with error assistance again.
I do have a question though: It does not appear that I am getting the e-mail passed to the first doc. Notice Doc: BOB does not have a corresponding Email:
Doc: George does have corresponding EMail: george.hamm@@gmail.com

 Code:
? "Elements in Docs Array: "+UBound($docs)
"Elements in Docs Array: "=UBound($docs)

If UBound($docs)>=0

$Root = CreateObject("Outlook.Application")
? "Outlook Creation: "+@Error
"Outlook Creation: "+@Error
Outlook Creation: 0

? "Doc: "+$Doc
"Doc: "+$Doc
$docemail = ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt", $doc, "Email")
Doc: BOB
? "Email: "+$docemail
"Email: "+$docemail
If Len($docemail)
Email:
Next
? "Doc: "+$Doc
"Doc: "+$Doc
$docemail = ReadProfileString("\\vsclinic2\mis\Reports\docmailer2010.txt", $doc, "Email")
Doc: GEORGE
? "Email: "+$docemail

"Email: "+$docemail
If Len($docemail)
Email: george.hamm@@gmail.com
$MailItem = $Root.CreateItem(0)
? "Root Creation: "+@Error
"Root Creation: "+@Error
$MailItem.Importance=1
Root Creation: 0

Top
#207549 - 2013-07-30 12:46 AM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Is that copied/pasted from the script or from the console after running? Don't understand why all of the variables we're not populated. Also, it looks like the email addresses still have 2 @@'s in them?
Top
#207552 - 2013-07-30 02:31 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
Stepping through the script is how I got the info.

Ran again this morning, I stopped when I hit the 3rd doc, and this is what I get as results (substituted fake names for real):

Outlook Creation: 0
Doc: BOB
Email:
Doc: GEORGE
Email: george.hamm@gmail.com
Root Creation: 0
Elements in Attachment Array: 7BOSWELL-anesnonunitdr-2013-06.pdf
Attachment: 0GEORGE-anesunitdr-2013-06.pdf
Attachment: 0GEORGE-Expense-2013-06.pdf
Attachment: 0GEORGE-Prof-Prod-2013-06.pdf
Attachment: 0GEORGE-Recap-2013-06.pdf
Attachment: 0GEORGE-SurveyResults-2013-06.pdf
Attachment: 0GEORGE-Work-RVU-2013-06.pdf
Attachment: 0Thumbs.db
Attachment: 0
Send: -2147352567
Doc: SAM

I stepped through the rest of the script. No e-mail shows up in the sent box in outlook.


Edited by Karon (2013-07-30 02:36 PM)
Edit Reason: finished running the script in debug mode.

Top
#207554 - 2013-07-30 05:12 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Found another typo.

Change this line
 Code:
$MailItem.To = $Email
to...
 Code:
$MailItem.To = $docemail

Top
#207555 - 2013-07-30 05:24 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
So - that got the e-mail going!
Still doesn't pull the e-mail for the first doc, therefore no attachments, or e-mail.
I did find another 2 typos in the txt file.... Helps if you can type the doctor name properly!!

Ran it and we are GOLDEN!!! You guys are the BEST! EVER!

Top
#207556 - 2013-07-30 05:45 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Awesome!
Top
#207558 - 2013-07-31 12:18 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
Can you post your final working copy in case others would like to reference it?
Top
#207559 - 2013-07-31 02:28 PM Re: Sendmail using outlook 2010 [Re: BradV]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
Brad - should I post it here or is there somewhere else I should post it? I will strip identifying information and replace with generic ie "<server>".
Top
#207560 - 2013-07-31 03:32 PM Re: Sendmail using outlook 2010 [Re: Karon]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
What you should do for your own code is use Variables and not embed hostnames or IPs in your code. This will allow you to easily modify this code in the future and share it with others by simply removing the variable definitions.

Posting it here would be appropriate. If you wish, send it to me as a PM and I'll format it and post it in the script vault, where there are several other "ready to use" scripts and script fragments.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 384 anonymous users online.
Newest Members
SERoyalty, mytar, Gabriel, Alex_Evos, Dansen
17869 Registered Users

Generated in 0.06 seconds in which 0.035 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org