#207483 - 2013-07-23 08:14 PM
Sendmail using outlook 2010
|
Karon
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:
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
|
|
|
|
#207485 - 2013-07-23 11:51 PM
Re: Sendmail using outlook 2010
[Re: Mart]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4545
Loc: USA
|
|
Top
|
|
|
|
#207489 - 2013-07-24 04:52 PM
Re: Sendmail using outlook 2010
[Re: Mart]
|
ShaneEP
MM club member
Registered: 2002-11-29
Posts: 2125
Loc: Tulsa, OK
|
Make sure to change... To $docs = Split($docs, "#")
|
Top
|
|
|
|
#207502 - 2013-07-26 02:17 PM
Re: Sendmail using outlook 2010
[Re: Mart]
|
Glenn Barnas
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:[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!
|
Top
|
|
|
|
#207515 - 2013-07-26 04:23 PM
Re: Sendmail using outlook 2010
[Re: Karon]
|
ShaneEP
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.
$rc = SetOption("NoMacrosInStrings","On")
|
Top
|
|
|
|
#207516 - 2013-07-26 04:28 PM
Re: Sendmail using outlook 2010
[Re: ShaneEP]
|
ShaneEP
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.
$files = DirList("\\server\share\folder",2)
For Each $file in $files
;;; Do what you need here
Next
|
Top
|
|
|
|
#207519 - 2013-07-26 05:18 PM
Re: Sendmail using outlook 2010
[Re: Karon]
|
ShaneEP
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.
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
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)"
When I use
$files = DirList("\\server\share\folder",2)
For Each $file in $files
;;; Do what you need here
my $files line reads:
$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
"\\server\share\(current month)" in the string? I have tried using '\' so that it shows as "\\server\share\\(current month\)" But it did not work.
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 507 anonymous users online.
|
|
|