Karon
(Getting the hang of it)
2013-07-23 08:14 PM
Sendmail using outlook 2010

I have a script that will send an e-mail, but it was created with an older version (4.20.0.0) of kixtart and ran oulook 2000. It was running on a windows 2003 server
I now have the same version of wkix32.exe, and outlook 2010 on a windows 7 pro 32bit pc and I am trying to get this working with no luck. Debug did not help much.
This is the script as I have altered it:

 Code:
If Exist ("\\<server>\home\smc\creditlist\creditmgr.xls")

		SendEmail ("IT Department", "Test E-mail", "Reply if you receive this".)

Else
  
	SendEmail ("IT Department", "Test E-mail", "Reply if you receive this - ind bad".)
                 
EndIf 

Function SendEmail ($Recip, $Subject, $Text)

	;Session.Logon now uses the default MAPI profile as found in the registry.
	
If @INWIN = 2
	; Windows 98 profile
	
	$DefaultProfile = 
		ReadValue("HKEY_CURRENT_USER\Software\Microsoft\" +
			"Windows Messaging Subsystem\Profiles", "DefaultProfile")
     
Else
     ; Windows 2000 profile
                
	$DefaultProfile = 
		ReadValue("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\" +
			"CurrentVersion\Windows Messaging Subsystem\Profiles", "DefaultProfile")
EndIf
			
	$Session = CreateObject("MAPI.Session")
	$Session.Logon($DefaultProfile)

	;Create the core MAPI objects--Message and Recipient

	$Message = $Session.Outbox.Messages.Add
	$Recipient = $Message.Recipients.Add
   
   ;Compose the message
   
   $Message.Subject = $Subject
   $Message.Text = $Text 
	
	;Translating email address so the '@' symbol doesn't confuse 
	;KiXtart as being a macro.This is better than having to remember
	;to Use '@@' in the Function argument, although either method will work.
	
	If InStr ($Recip, "<unknown:") <> 0
		
		$Recip = SubStr($Recip, 1, InStr($Recip, "<unknown:") - 1) + "@@" +  
					SubStr($Recip, InStr($Recip, "<unknown:") + 9, Len($Recip))
					
	EndIf	
	
	;Select recipient
	;	Note:	Recipient.Type values are as follows:
	;			1 = To
	;			2 = Cc
	;			3 = Bcc			
	
	$Recipient.Name = $Recip
	$Recipient.Type = 1
	$Recipient.Resolve
   
   ;Sending the message
   
   $Message.Send
   
   $Session.DeliverNow
   
   ;Disconnecting MAPI Session
   
   $Session.Logoff
   
   ;Object Cleanup
   
   $Recipient = 0
   $Message = 0
   $Session = 0

EndFunction    


I think the problem is that outlook 2000 invoked MAPI, but I don't know what 2010 uses.
If I cannot use outlook 2010, I will need to use 2007 and try again.
Thanks in advance.


Mart
(KiX Supporter)
2013-07-23 11:06 PM
Re: Sendmail using outlook 2010

You can use Outlook 2010. I'm switching from using Blat.exe to using regular Outlook. Works fine with Outlook 2010 and it saves the message to sent items which is also nice.......in most cases.

 Code:
$Root = CreateObject("Outlook.Application")
$MailItem = $Root.CreateItem(0)
$MailItem.Importance = 1
; - 2 high importance
; - 1 normal importance
; - 0 low importance
$MailItem.Subject = "Test"
$MailItem.Sender = "sender@@domain.com"
$MailItem.To = "recipient@@domain.com"
$MailItem.Body = "Test body text"
If Exist("C:\some folder\some file.txt")
	$MailItem.Attachments.Add("C:\some folder\some file.txt")
EndIf
$MailItem.Send
$Root = 0


AllenAdministrator
(KiX Supporter)
2013-07-23 11:51 PM
Re: Sendmail using outlook 2010

If you want to avoid Blat or Outlook, and just use SMTP...

Sendmail -
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=201907#Post201907


Karon
(Getting the hang of it)
2013-07-24 03:40 PM
Re: Sendmail using outlook 2010

Wahoo! That did it!!!
Many thanks as this is going to make some doctors happy.
Next question - how can I use a text file of addresses?
I have to send different files to about 15 doctors and I have the text file created.

this is an example:

folder,email
doc1,doc1@yahoo.com

I am betting I need to change line one in the text
and I know I will need to change the '$MailItem.To = "recipient@@domain.com"' to point to the file, but I cannot find the post regarding this - I saw one out there somewhere.. dangit.

Also there are multiple attachments:
$attach[0],
"$home$folder\(current month)\"+$attach[0],
$attach[1],
"$home$folder\(current month)\"+$attach[1],
the $home and $folder are previously defined.
should I just use

$MailItem.Attachments.Add($home$folder\(current month)\*.*)
??

Thanks a bunch!!


Mart
(KiX Supporter)
2013-07-24 04:16 PM
Re: Sendmail using outlook 2010

Using an INI file with the e-mail and other data would make it much easier. Below is an example. It is not the most clean or advanced code but it is just a proof of concept.
Up until now I could not get the sender address set to anything else then the user that is running the script so I commented that line.

Sample INI file
 Quote:

[Docs]
names=Doc1#Doc2#Doc3

[Doc1]
email=doc1@@domain.com
[Doc2]
email=doc2@@domain.com
[Doc3]
email=doc3@@domain.com


Sample script:
 Code:
Break on

$docs = ReadProfileString("SomeINIFile.ini", "Docs", "Names")
$docs = Split($docs, "#")

For Each $doc in $docs
	$docemail = ReadProfileString("SomeINIFile.ini", $doc, "Email")
		
	$Root = CreateObject("Outlook.Application")
	$MailItem = $Root.CreateItem(0)
	$MailItem.Importance = 1
	; - 2 high importance
	; - 1 normal importance
	; - 0 low importance
	$MailItem.Subject = "Test"
	;$MailItem.Sender = "sender@@domain.com"
	$MailItem.To = $docemail
	$MailItem.Body = "Test body text"
	If Exist("C:\some folder\some file.txt")
		$MailItem.Attachments.Add("C:\some folder\some file.txt")
	EndIf
	$MailItem.Send
	$Root = 0
Next


ShaneEP
(MM club member)
2013-07-24 04:52 PM
Re: Sendmail using outlook 2010

Make sure to change...
 Code:
$docs = Split($docs, "#)

To
 Code:
$docs = Split($docs, "#")


Mart
(KiX Supporter)
2013-07-24 05:06 PM
Re: Sendmail using outlook 2010

 Originally Posted By: ShaneEP
Make sure to change...
 Code:
$docs = Split($docs, "#)

To
 Code:
$docs = Split($docs, "#")


woops. Fixed in the code above.


Karon
(Getting the hang of it)
2013-07-25 11:16 PM
Re: Sendmail using outlook 2010

Sample ini file:

[Docs]
names=BOB#GEORGE#SAM#

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

None of the above are real e-mail accounts that I know of. I just made them up.
Is there supposed to be a '#' at the end of the doctor list?

Also can I use '*.*' to signify ALL files in a folder?


Mart
(KiX Supporter)
2013-07-26 08:30 AM
Re: Sendmail using outlook 2010

You do not need an extra # at the end of the doctor list. If you do have it it will try to send the last mail to an empty recipient address which will obviously fail.

Why would you specify all files in a folder? Do you need to attach them all to the e-mail?


Glenn BarnasAdministrator
(KiX Supporter)
2013-07-26 02:17 PM
Re: Sendmail using outlook 2010

A slight simplification that will cut the size of the INI file is to use an EMAIL section and one or more Distribution List sections, like this:
 Code:
[DIST LISTS]
OBGYN=doc1,doc3,doc11
TRAMUA=doc7,doc4,doc15

[EMAIL]
Doc1=Tuna.Turner@motown.com
Doc2=Francine.flounder@ocean.org
Doc3=GeoGrouper@ocean.org
In this way, you could extract the list of users from a specific group, enumerate them from a single section of email addresses. Having multiple sections for the doctors would be efficient only if you had multiple data types for each one (name, department, email, location, etc..)

Not much of a difference in the code, so I won't repeat that.. just changes to the ReadProfileString function args.

Glenn


Karon
(Getting the hang of it)
2013-07-26 02:44 PM
Re: Sendmail using outlook 2010

Yes I need to attach them all.

Karon
(Getting the hang of it)
2013-07-26 02:52 PM
Re: Sendmail using outlook 2010

Will I need a single '@' or a double '@@'??
I do have different e-mail address and they each get their own reports, so I can use a distro list. THAT would have been great!


Mart
(KiX Supporter)
2013-07-26 03:18 PM
Re: Sendmail using outlook 2010

Sometimes you do and sometimes you do not need the double @. Kix has macros that start with @ so it may try to resolves them resulting in an invalid e-mail address. Doubling up on the @ will prevent kix from trying to resolve them.

Adding the files is not that difficult. You cannot just say attach *.* but you can loop through a folder and add them one by one to one e-mail.
Heading home now. It was a long day yesterday 8:30am to 0:30am and this morning a drain pipe of one of the air conditioning systems broke off spraying water into some servers. Servers are dead, restoring backups now so I'm heading home and I'll finish everything from there.

if I get some time I'll post something looping through the folder and adding all files in it.


Karon
(Getting the hang of it)
2013-07-26 03:22 PM
Re: Sendmail using outlook 2010

Good luck and get some sleep!
I look forward to the "looping" code, because what I had for the old kix doesn't work on the new.... <sigh>


ShaneEP
(MM club member)
2013-07-26 04:23 PM
Re: Sendmail using outlook 2010

If you set the no macros option at the beginning of your script, you shouldn't have to worry about using 2 @'s. Just add the following line at the beginning of your script.
 Code:
$rc = SetOption("NoMacrosInStrings","On")


ShaneEP
(MM club member)
2013-07-26 04:28 PM
Re: Sendmail using outlook 2010

As for the multiple files...The DirList() UDF works well. Here's a rough example of how to use it.

 Code:
$files = DirList("\\server\share\folder",2)
For Each $file in $files
  ;;;  Do what you need here
Next


Karon
(Getting the hang of it)
2013-07-26 04:50 PM
Re: Sendmail using outlook 2010

What I need to do is attach each to an e-mail...

ShaneEP
(MM club member)
2013-07-26 05:18 PM
Re: Sendmail using outlook 2010

Yeah, I had gathered that much. Just figured you might be able to take the initiative to figure the rest out. But here is how I would do it...Using the ini file configuration that Mart had posted previously.

 Code:
Break on
$rc = SetOption("NoMacrosInStrings","On")
$rc = SetOption("NoVarsInStrings","On")

$docs = Split(ReadProfileString("SomeINIFile.ini", "Docs", "Names"),"#")

If UBound($docs)>=0
	$Root = CreateObject("Outlook.Application")
	For Each $doc in $docs
		$docemail = ReadProfileString("SomeINIFile.ini", $doc, "Email")
                If Len($docemail)
			$MailItem = $Root.CreateItem(0)
			$MailItem.Importance = 1
			$MailItem.Subject = "Test"
			$MailItem.To = $docemail
			$MailItem.Body = "Test body text"
	        	$Attachments = DirList("\\server\share\(current month)",2)
			If UBound($attachments)>=0
				For Each $attachment 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


Karon
(Getting the hang of it)
2013-07-29 03:06 PM
Re: Sendmail using outlook 2010

This is working great! Now- I have a folder name of "(current month)"

 Code:
When I use 
$files = DirList("\\server\share\folder",2)
For Each $file in $files
  ;;;  Do what you need here


my $files line reads:
 Code:
$files = DirList("\\server\share\(current month)",2)


I get an error that there is a missing ')'.
What is the escape character so I can use
 Code:
"\\server\share\(current month)"

in the string? I have tried using '\' so that it shows as
 Code:
"\\server\share\\(current month\)"

But it did not work.


AllenAdministrator
(KiX Supporter)
2013-07-29 04:08 PM
Re: Sendmail using outlook 2010

Did you copy the Dirlist UDF to your script?

Karon
(Getting the hang of it)
2013-07-29 04:10 PM
Re: Sendmail using outlook 2010

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!)


AllenAdministrator
(KiX Supporter)
2013-07-29 04:19 PM
Re: Sendmail using outlook 2010

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


Glenn BarnasAdministrator
(KiX Supporter)
2013-07-29 05:51 PM
Re: Sendmail using outlook 2010

There's "Fundamentals of Programming" document on my web site that might be helpful as well. In the Resources section.

Glenn


Karon
(Getting the hang of it)
2013-07-29 06:17 PM
Re: Sendmail using outlook 2010

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
  


ShaneEP
(MM club member)
2013-07-29 09:17 PM
Re: Sendmail using outlook 2010

I see you're using a .txt file for the information. Is the file structured in an INI format?

Karon
(Getting the hang of it)
2013-07-29 09:19 PM
Re: Sendmail using outlook 2010

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


ShaneEP
(MM club member)
2013-07-29 09:26 PM
Re: Sendmail using outlook 2010

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)


ShaneEP
(MM club member)
2013-07-29 09:28 PM
Re: Sendmail using outlook 2010

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"


Karon
(Getting the hang of it)
2013-07-29 09:58 PM
Re: Sendmail using outlook 2010

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>


ShaneEP
(MM club member)
2013-07-29 11:01 PM
Re: Sendmail using outlook 2010

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


Karon
(Getting the hang of it)
2013-07-30 12:09 AM
Re: Sendmail using outlook 2010

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


ShaneEP
(MM club member)
2013-07-30 12:46 AM
Re: Sendmail using outlook 2010

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?

Karon
(Getting the hang of it)
2013-07-30 02:31 PM
Re: Sendmail using outlook 2010

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.


ShaneEP
(MM club member)
2013-07-30 05:12 PM
Re: Sendmail using outlook 2010

Found another typo.

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


Karon
(Getting the hang of it)
2013-07-30 05:24 PM
Re: Sendmail using outlook 2010

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!


ShaneEP
(MM club member)
2013-07-30 05:45 PM
Re: Sendmail using outlook 2010

Awesome!

BradV
(Seasoned Scripter)
2013-07-31 12:18 PM
Re: Sendmail using outlook 2010

Can you post your final working copy in case others would like to reference it?

Karon
(Getting the hang of it)
2013-07-31 02:28 PM
Re: Sendmail using outlook 2010

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>".

Glenn BarnasAdministrator
(KiX Supporter)
2013-07-31 03:32 PM
Re: Sendmail using outlook 2010

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