WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Reggie

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get SMTP Mail Server


Here is some code that attempts to track down the SMTP mail server in the registry.

Note: It requires the Reggie Extender.

Code tested on Windows XP, 2000 and Windows 95

#DefineFunction Hex2Dec(hex)
   str="0123456789ABCDEF"
   hex=StrTrim(StrUpper(hex))
   hexlen=StrLen(hex)
   dec=0
   for x=1 to hexlen
       dec=(dec*16) + StrIndex(str,strsub(hex,x,1),0,@fwdscan) -1
   next
   return(dec)
#EndFunction


#DefineFunction GetSMTPServer()
	AddExtender("WWREG34I.DLL")

	srchstr="SMTP Server"  
	topkey=@REGCURRENT    
	topsub="\"
	looktype=0             
	lookat=7       
	dosubtree=@FALSE        
	smtppathlist=rRegSearch(topkey,topsub,srchstr,looktype,lookat,dosubtree)
	if smtppathlist == ""
		Message("Error",StrCat(srchstr," Not found in registry"))
		return smtppathlist
	endif
   smtpservers = ""
   For x = 1 to ItemCount(smtppathlist,@Tab)
      smtppath = ItemExtract(x,smtppathlist,@Tab)
   	;remove leading '\'
   	if StrSub(smtppath, 1, 1)=="\" 
   		 smtppath = StrSub(smtppath, 2, -1)
   	endif
   	
   	;Read data from registy
   	datatype = RegEntryType(topkey,smtppath)
   	data = RegQueryEx (topkey, smtppath, "", datatype)
   	smtpserver = ""
   	Switch datatype
   		case 3 ; REG_BINARY 
   			;Convert hex bin data to ansi string
   			For i = 1 to ItemCount(data," ")
   				hex = ItemExtract(i,data," ")
   				if hex == "00" then continue
   				dec = Hex2Dec(hex)
   				char = Num2Char(dec)
   				smtpserver = StrCat(smtpserver,char)
   			Next
   		break
   		case datatype  ;Any other REG_ type
   			smtpserver = data
   		break
   	EndSwitch

      if x == 1 then smtpservers = smtpserver
      else smtpservers = StrCat(smtpservers,@tab,smtpserver)
   Next
   return smtpservers
#EndFunction




smtpserver = GetSMTPServer()
if smtpserver == ""
  smtpserver = ("My Emailer", "Please enter the name of your SMTP Server", "")
endif
Message("SMTP Server",smtpserver)
exit


Article ID:   W15869
File Created: 2005:01:14:11:11:02
Last Updated: 2005:01:14:11:11:02