Page 1 of 1 1
Topic Options
#188335 - 2008-06-24 02:42 PM Setting the deafult e-mailaddress
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
We have an issue where it would be great if a user could set his/her own default e-mail address.

Let’s say a user has three e-mail addresses one is the default and the other two are aliases. Is it then possible to set the default as an alias and set an alias as the default via a script?
Did some googling on this but did not find anything useful yet.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188336 - 2008-06-24 04:56 PM Re: Setting the deafult e-mailaddress [Re: Mart]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
I think the way PayPal handles this, for example.. They send an e-mail to all of the addresses you define.

The only purpose that I can see with this (personally).. If you forget your password and need to have it send you the unlock link and your e-mail address has changed..

Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188340 - 2008-06-24 07:01 PM Re: Setting the deafult e-mailaddress [Re: Kdyer]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hi Kent. Long time no see. Hope all is ok.

Maybe I should explain this a bit more.

Some of our employees work for our OfficeA and OfficeB but are employed by OfficeA so user@OfficeA.nl is the default e-mail address on our exchange server. When they do work for OfficeB and therefore need to send an e-mail to a customer or supplier they want to send it from user@OfficeB.nl. Sure you can use the from field in outlook but that automatically translates to your default e-mail address and does not hold the address if you typed an alias in the from field. One way to "fix" this without me switching it in AD 10 times a day would be to create an kixforms app that the user can fire up, list all e-mail addresses he/she has, select the one to be default, click ok and have the script switch the current default to an alias and set the selected address as default. Just like you can do in the e-mail addresses tab in the user’s properties in AD.

Oh BTW we use Win2K and Exchange 2K just in case stuff is a bit different in 2K3 or even 2K8.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188342 - 2008-06-25 03:58 AM Re: Setting the deafult e-mailaddress [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
I found something interesting... will pass this along asap.

[Edit... I've come up with some UDFs, but will try to test with Mart, before posting]


Edited by Allen (2008-06-25 07:44 AM)

Top
#188345 - 2008-06-25 09:18 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Oooohhh... sounds good. I'd be happy do do some testing. I just send you a PM.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188346 - 2008-06-25 10:32 AM Re: Setting the deafult e-mailaddress [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Got something going to get all e-mail addresses some time ago.
Only thing missing is the code to change an alias into the default and the default into an alias.

 Code:
Break on

$rc = SetOption('Explicit','On')
$rc = SetOption('NoVarsInStrings','On')
$rc = SetOption('NoMacrosInStrings','On')

Dim $adsDomain, $adsUser, $cnusr, $usrnfo, $usrmail, $type
$adsDomain = GetObject("WinNT://"+@LDOMAIN)
$adsDomain.filter = "User",""
For Each $adsUser in $adsDomain
	$cnusr = TranslateName($adsUser.Name)
	$usrnfo = GetObject("LDAP://"+$cnusr)
	For Each $usrmail in $usrnfo.proxyAddresses
		If Left($usrmail, 5) <>  "X400:"
			If $adsUser.Name = @USERID
				$type = Left($usrmail, 3)
				If LCase($type) == $type
					$type = "Alias"
				Else
					$type = "Default"
				EndIf
				? $adsUser.Name " : " $usrmail " : " $type
			EndIf
		EndIf
	Next
Next
Sleep 5

Function TranslateName($NameToTranslate)
	Dim $NameTranslate
	$NameTranslate = CreateObject("NameTranslate")
	$NameTranslate.Init(3,"")
	$NameTranslate.Set(3, @LDOMAIN + "\" + $NameToTranslate)
	$TranslateName = $NameTranslate.Get(1)
EndFunction
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188388 - 2008-06-26 02:27 PM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
[edit]
Removed stupid code.
Examples below are much nicer.
[/edit]


Edited by Mart (2008-06-30 09:09 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188397 - 2008-06-26 05:27 PM Re: Setting the deafult e-mailaddress [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Okay... here is what I have... the start of 3 new UDFs. The getUserDN may already exist somewhere [edit: ahh... so this is what TranslateName() does. /edit], so I may have reinvented the wheel. The UDFs still need some cleanup, debugging, etc, but should be working. As we discussed, the AD perms may be an issues with the SET udf.

break on
$=setoption("NoMacrosinstrings","on")


for each $email in getemailaddresses() ; current user
? $email
next
?
$defaultemailaddress=GetemailAddresses()[0] ;current user
? $defaultemailaddress


for each $email in getemailaddresses("johndoe") ; define the username
? $email
next




Function getUserDN($username)
;http://www.rlmueller.net/NameTranslateFAQ.htm
Dim $objTrans
$objTrans = CreateObject("NameTranslate")
if @error
exit @error
else
$objTrans.Init(3, "")
$objTrans.Set(3, @ldomain + "\" + $username)
$getUserDN = $objTrans.Get(1)
if @error
exit @error
endif
endif
EndFunction


function GetEmailAddresses(optional $user)
dim $addys[0], $objuser, $objsysinfo, $email, $i
if $user
$ObjUser=GetObject("LDAP://" + GetUserDN($user))
else
$objSysInfo = CreateObject("ADSystemInfo")
$objUser=getobject("LDAP://" + $objSysInfo.UserName)
endif
For each $email in $objUser.proxyAddresses
select
case left($email,4)=="SMTP"
$addys[0]=right($email,-5)
case left($email,4)=="smtp"
$i=$i+1
redim preserve $addys[$i]
$addys[$i]=right($email,-5)
endselect
Next
$GetEmailAddresses=$addys
endfunction



function SetDefaultEmailAddress($defaultemail,optional $user)
dim $addys[0], $objuser, $objsysinfo, $email, $i
if $user
$ObjUser=GetObject("LDAP://" + GetUserDN($user))
else
$objSysInfo = CreateObject("ADSystemInfo")
$objUser=getobject("LDAP://" + $objSysInfo.UserName)
endif
For each $email in $objUser.proxyAddresses
select
case right($email,-5)=$defaultemail
$addys[0]="SMTP:" + $defaultemail
case left($email,4)="smtp"
$i=$i+1
redim preserve $addys[$i]
$addys[$i]="smtp:" + right($email,-5)
case 1
$i=$i+1
redim preserve $addys[$i]
$addys[$i]=$email
endselect
Next
if $addys[0]
;$setdefaultemailaddress=$addys
$objUser.proxyAddresses=$addys
$objUser.setinfo
endif
endfunction

Top
#188420 - 2008-06-27 10:34 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Sweet
I'll look into it today and let you know how it comes along.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188421 - 2008-06-27 11:52 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Allen,

Very cools stuff. Works great
But like you said a regular user cannot set his/her default e-mail address. I did some testing with a user I created especially for this and it did work when on the security tab in the user's properties in AD I added write to SELF. A security risk, I know. I’m looking at the consequences that this might have. Hmmmmmm…
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188486 - 2008-06-30 09:18 PM Re: Setting the deafult e-mailaddress [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Made a KF.NET GUI around this. It’s not completely done just yet but I’ll post the code later this week.

What does it do?
  • gets the current default e-mail address.
  • lists all SMTP aliases.
  • refreshes the current default address when you set it.
  • refreshes the aliases list when you set a new default address.
  • lets you select a user. You must be a member of the Domain Admins group). If you a not a member only the default address for @USERID can be changed.
  • tells you if the user has no e-mail or no aliases.
  • checks to see if the default address was actually changed (privileges issue).
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188569 - 2008-07-04 11:51 PM Re: Setting the deafult e-mailaddress [Re: Mart]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
So Mart / Allen I notice that you went with the the SMTP entry as being the default e-mail. Was there no way to read the "mail" entry? It looks like this might be returned as an object instead of a string though.
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188570 - 2008-07-05 03:10 AM Re: Setting the deafult e-mailaddress [Re: Gargoyle]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
In this case, Mart was looking to get all the email addresses, AND the default. The uppercase SMTP is always supposed to be the default, so it kind of was just a matter of checking it. .mail should be no different though.
Top
#188577 - 2008-07-07 07:59 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
@Mart... would you mind testing these versions out... I added some error checking/etc.

function SetDefaultEmailAddress($defaultemail,optional $user)
dim $addys[0], $objuser, $objsysinfo, $email, $i, $rc
$setdefaultemailaddress=-1
if $user
$ObjUser=GetObject("LDAP://" + GetUserDN($user))
if @error
exit @error
endif
else
$objSysInfo = CreateObject("ADSystemInfo")
$objUser=getobject("LDAP://" + $objSysInfo.UserName)
endif
For each $email in $objUser.proxyAddresses
select
case right($email,-5)=$defaultemail
$addys[0]="SMTP:" + $defaultemail
case left($email,4)="smtp"
$i=$i+1
redim preserve $addys[$i]
$addys[$i]="smtp:" + right($email,-5)
case 1
$i=$i+1
redim preserve $addys[$i]
$addys[$i]=$email
endselect
Next
if $addys[0]
$objUser.proxyAddresses=$addys
$objUser.setinfo
$rc=@error
if $rc
$setdefaultemailaddress=$rc
exit $rc
endif
$setdefaultemailaddress=0
endif
endfunction






function GetEmailAddresses(optional $user)
dim $addys[0], $objuser, $objsysinfo, $email, $i
if $user
$ObjUser=GetObject("LDAP://" + GetUserDN($user))
if @error
exit @error
endif
else
$objSysInfo = CreateObject("ADSystemInfo")
$objUser=getobject("LDAP://" + $objSysInfo.UserName)
endif
For each $email in $objUser.proxyAddresses
select
case left($email,4)=="SMTP"
$addys[0]=right($email,-5)
case left($email,4)=="smtp"
$i=$i+1
redim preserve $addys[$i]
$addys[$i]=right($email,-5)
endselect
Next
$GetEmailAddresses=$addys
endfunction

Top
#188578 - 2008-07-07 08:06 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Gargoyle Offline
MM club member
*****

Registered: 2004-03-09
Posts: 1597
Loc: Valley of the Sun (Arizona, US...
Allen,
Would you mind eloborating on the "ADSystemInfo" object. I have only worked really with the "WinNT" and "LDAP" objects.

I am assuming that this line of your code "$objUser=getobject("LDAP://" + $objSysInfo.UserName)" is returning the the entire User properties. Else how is it that the ".proxyaddresses" is being returned as an array within the properties of the user.

I can trust that the code you have works (it usually does), but want a better understanding of what I am working with.

Many thanks
G
_________________________
Today is the tomorrow you worried about yesterday.

Top
#188579 - 2008-07-07 08:20 AM Re: Setting the deafult e-mailaddress [Re: Gargoyle]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
 Code:
$objSysInfo = CreateObject("ADSystemInfo")
$objUser=getobject("LDAP://" +  $objSysInfo.UserName)


When you are only interested in the current user, this is just a different way/shortcut to get the DN, rather than using the TranslateName UDF (nametranslate object) . Truthfully, you could use the Translatename exclusively if you wanted to.

Its creating two objects, one with the ADSystemInfo, and then another when you use the LDAP provider with .username. This gives you all the properties of the current user, including the proxyaddresses.

Clear as mud?

Top
#188582 - 2008-07-07 10:38 AM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Quote:

@Mart... would you mind testing these versions out... I added some error checking/etc.
....


Will do but it will have to wait until tomorrow. I’m in the office for just a few hours today and some work is waiting.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188604 - 2008-07-08 11:50 AM Re: Setting the deafult e-mailaddress [Re: Mart]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Allen,

They seem to work just fine.

The reason why I didn't post the GUI code yet is that I get loads of return codes on the screen when lines are added to a ComboBox. Couldn't find the reason for this yet have to figure that one out.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188625 - 2008-07-09 07:08 AM Re: Setting the deafult e-mailaddress [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Cool... thanks for testing them. What have you guys decided on the perms? The reason I ask is... I have another UDF that might make you reconsider allowing changes
Top
#188628 - 2008-07-09 12:24 PM Re: Setting the deafult e-mailaddress [Re: Allen]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
We decided not to change any perms until the user needs to be able to change his/her default address then we give the SELF user write privileges. As soon as he/she no longer needs this we remove the permissions and set it back to how it was before the change (default is read only).

So you have an other UDF that will make me reconsider? Hmmmm....wathya doing? Trying to make me cry?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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.076 seconds in which 0.023 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