Page 1 of 2 12>
Topic Options
#207483 - 2013-07-23 08:14 PM Sendmail using outlook 2010
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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.


Edited by Mart (2013-07-23 11:01 PM)
Edit Reason: Please use code tags when posting code.

Top
#207484 - 2013-07-23 11:06 PM Re: Sendmail using outlook 2010 [Re: Karon]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207485 - 2013-07-23 11:51 PM Re: Sendmail using outlook 2010 [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
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

Top
#207487 - 2013-07-24 03:40 PM Re: Sendmail using outlook 2010 [Re: Mart]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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!!

Top
#207488 - 2013-07-24 04:16 PM Re: Sendmail using outlook 2010 [Re: Karon]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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


Edited by Mart (2013-07-24 05:05 PM)
Edit Reason: Typo in the code. Thanks Shane.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207489 - 2013-07-24 04:52 PM Re: Sendmail using outlook 2010 [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
Make sure to change...
 Code:
$docs = Split($docs, "#)

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

Top
#207490 - 2013-07-24 05:06 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: ShaneEP
Make sure to change...
 Code:
$docs = Split($docs, "#)

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


woops. Fixed in the code above.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207495 - 2013-07-25 11:16 PM Re: Sendmail using outlook 2010 [Re: Mart]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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?

Top
#207497 - 2013-07-26 08:30 AM Re: Sendmail using outlook 2010 [Re: Karon]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207502 - 2013-07-26 02:17 PM Re: Sendmail using outlook 2010 [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
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
_________________________
Actually I am a Rocket Scientist! \:D

Top
#207503 - 2013-07-26 02:44 PM Re: Sendmail using outlook 2010 [Re: Mart]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
Yes I need to attach them all.
Top
#207505 - 2013-07-26 02:52 PM Re: Sendmail using outlook 2010 [Re: Glenn Barnas]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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!

Top
#207507 - 2013-07-26 03:18 PM Re: Sendmail using outlook 2010 [Re: Karon]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
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.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#207510 - 2013-07-26 03:22 PM Re: Sendmail using outlook 2010 [Re: Mart]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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>

Top
#207515 - 2013-07-26 04:23 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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")

Top
#207516 - 2013-07-26 04:28 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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

Top
#207518 - 2013-07-26 04:50 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
What I need to do is attach each to an e-mail...
Top
#207519 - 2013-07-26 05:18 PM Re: Sendmail using outlook 2010 [Re: Karon]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
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


Edited by ShaneEP (2013-07-29 04:33 PM)

Top
#207533 - 2013-07-29 03:06 PM Re: Sendmail using outlook 2010 [Re: ShaneEP]
Karon Offline
Getting the hang of it

Registered: 2009-07-16
Posts: 87
Loc: Texas
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.

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

Registered: 2003-04-19
Posts: 4545
Loc: USA
Did you copy the Dirlist UDF to your script?
Top
Page 1 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 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.075 seconds in which 0.024 seconds were spent on a total of 14 queries. Zlib compression enabled.

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