Sign in to follow this  
Followers 0
Exit

How to get own default e-mail address ?

74 posts in this topic

#1 ·  Posted (edited)

Is there a simple method to get the own default e-Mail address ?

My current way is to call browsers "Mailto:" and fiddle through the menus to copy my e-mail address.

There must be an easier way to get this info. Perhaps registry or appl-data ?

Any hint?

EDIT: Made a solution at least for

Microsoft Outlook, Outlook Express, Windows Life Mail, Mozilla Thunderbird and Pegasus Mail

MsgBox(64 + 262144, " Your e-mail account", _
"Your e-mail program is >" & _Get_Email_Client() & "<" & @LF & @LF & _
"Your e-mail address is >" & _Get_Email_Address() & "<", 0)
;
Func _Get_Email_Address()
 $sEmailClient = _Get_Email_Client()
 Switch $sEmailClient
  Case "Microsoft Outlook"
   $sEmailAccount = _Get_Microsoft_Outlook_Account()
  Case "Outlook Express"
   $sEmailAccount = _Get_Outlook_Express_Account()
  Case "Windows Live Mail"
   $sEmailAccount = _Get_Windows_Live_Mail_Account()
  Case "Mozilla Thunderbird"
   $sEmailAccount = _Get_Mozilla_Thunderbird_Account()
  Case "Pegasus Mail"
   $sEmailAccount = _Get_Pegasus_Mail_Account()
  Case "eM Client"
   $sEmailAccount = _Get_eM_Client_Account()
  Case "Other Client" ; feel free to add the solution for your e-mail client
   $sEmailAccount = _Get_Other_Client_Account()
  Case Else
   $sEmailAccount = "not found"
 EndSwitch
 Return $sEmailAccount
EndFunc   ;==>_Get_Email_Address
;
Func _Get_Email_Client()
 $sClient = RegRead("HKEY_CURRENT_USER\Software\Clients\Mail", "")
 If @error Then $sClient = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "")
 If @error Then Return "not found"
 Return $sClient
EndFunc   ;==>_Get_Email_Client
;
Func _Get_Microsoft_Outlook_Account()
 $sAccount = "not found"
 $result = _RegSearch("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\", "NextAccountID")
 For $j = 1 To 9999
  $varname = RegEnumVal($result[0], $j)
  If @error = -1 Then ExitLoop
  If Not (StringLeft($varname, 1) = "{") Then ContinueLoop
  $ids = RegRead($result[0], $varname)
  If @error Then ContinueLoop
  $email = RegRead($result[0] & "\" & Hex(Int(BinaryMid($ids, 1, 4))), "Email")
  If @error Then ContinueLoop
  $sAccount = StringTrimRight(BinaryToString($email, 2), 1)
  ExitLoop
 Next
 Return $sAccount
EndFunc   ;==>_Get_Microsoft_Outlook_Account
;
Func _Get_Outlook_Express_Account()
 $sAccountIndex = RegRead("HKCU\Software\Microsoft\Internet Account Manager", "Default Mail Account")
 $sAccount = RegRead("HKCU\Software\Microsoft\Internet Account Manager\Accounts\" & $sAccountIndex, "SMTP Email Address")
 If @error Then $sAccount = "not found"
 Return $sAccount
EndFunc   ;==>_Get_Outlook_Express_Account
;
Func _Get_Windows_Live_Mail_Account()
 $sAccount = "not found"
 $sAccountroot = RegRead("HKCU\Software\Microsoft\Windows Live Mail", "Store Root")
 $sAccountFile = RegRead("HKCU\Software\Microsoft\Windows Live Mail", "Default Mail Account")
 $Opt = Opt("ExpandEnvStrings", 1)
 $hSearch = FileFindFirstFile($sAccountroot & "\*.*")
 If Not @error Then
  While 1
   $sFile = FileFindNextFile($hSearch)
   If @error Then ExitLoop
   If @extended Then
    $sAccountProfile = FileRead($sAccountroot & "\" & $sFile & "\" & $sAccountFile)
    If Not @error Then ExitLoop
   EndIf
  WEnd
  FileClose($hSearch)
 EndIf
 Opt("ExpandEnvStrings", $Opt)
 $t = StringSplit($sAccountProfile, '</SMTP_Email_Address>', 1)
 If Not @error Then $t = StringSplit($t[1], '<SMTP_Email_Address type="SZ">', 1)
 If Not @error Then $sAccount = $t[$t[0]]
 Return $sAccount
EndFunc   ;==>_Get_Windows_Live_Mail_Account
;
Func _Get_Mozilla_Thunderbird_Account()
 ; Case "Mozilla Thunderbird"
 $ini = IniRead(@AppDataDir & "\Thunderbird\profiles.ini", "Profile0", "Path", "")
 $text = FileRead(@AppDataDir & "\Thunderbird\" & $ini & "\prefs.js")
 $sAccount = "not found"
 $t = StringSplit($text, 'accountmanager.defaultaccount", "', 1)
 If Not @error Then $t = StringSplit($t[2], '"', 1)
 If Not @error Then $defAccount = $t[1]
 $t = StringSplit($text, $defAccount & '.server", "', 1)
 If Not @error Then $t = StringSplit($t[2], '"', 1)
 If Not @error Then $defServer = $t[1]
 $t = StringSplit($text, $defServer & '.name", "', 1)
 If Not @error Then $t = StringSplit($t[2], '"', 1)
 If Not @error Then $sAccount = $t[1]
 Return $sAccount
EndFunc   ;==>_Get_Mozilla_Thunderbird_Account
;
Func _Get_Pegasus_Mail_Account()
 ; Case "Pegasus Mail"
 $sMailbox = RegRead("HKEY_CURRENT_USER\Software\Pegasus Mail\Mailbox", "")
 If @error Then $sMailbox = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Pegasus Mail\Mailbox", "")
 $sAccount = IniRead($sMailbox & "\Pmail.ini", "Pegasus Mail for Windows", "Internet E-mail Address", "???")
 Return $sAccount
EndFunc   ;==>_Get_Pegasus_Mail_Account
;
Func _Get_eM_Client_Account()
 ; Case "eM Client"
 Return "not found"
EndFunc   ;==>_Get_eM_Client_Account
;
Func _Get_Other_Client_Account()
 Return "_Get_Other_Client_Account() under construction"
EndFunc   ;==>_Get_Other_Client_Account
;
Func _RegSearch($RegPath, $RegVar)
 Local $Return[3], $subkey, $Var
 For $i = 1 To 9999999
  $Var = RegEnumVal($RegPath, $i)
  If @error = -1 Then ExitLoop
  If $Var = $RegVar Then Return StringSplit($RegPath & @LF & $Var & @LF & RegRead($RegPath, $Var), @LF, 2)
 Next
 For $i = 1 To 9999999
  $subkey = $RegPath & "\" & RegEnumKey($RegPath, $i)
  If @error = -1 Then ExitLoop
  $Return = _RegSearch($subkey, $RegVar)
  If $Return[0] Then ExitLoop
 Next
 Return $Return
EndFunc   ;==>_RegSearch
;
; end of script

Any solutions for other mail clients feasible ? :idea::thumbsup:

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites



Did you forget it?

1 person likes this

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Hi Exit

I'm afraid the only way I've thought of doing it is to get a piece of code like yours for each of the different types of Email clients.

Outlook, Outlook Express, Windows Mail, Windows Live Mail, thunderbird, etc

Alternatively you could use "Mail PassView" by Nir Sofer. However, MOST antivirus programs will make it as a hacker tool as it also shows passwords.

The other problem is many computers have multiple Email address. How are you going to work out which is the right one?

I'm interested in this myself as it would save me having to type in email addresses for customers when I register their software. Many look at me blank when I ask them what their email address is.....sigh

Let me know if you find a good solution to the problem.

John Morrison

Share this post


Link to post
Share on other sites

Hi Exit I'm afraid the only way I've thought of doing it is to get a piece of code like yours for each of the different types of Email clients. Outlook, Outlook Express, Windows Mail, Windows Live Mail, thunderbird, etc

Hi John,

yes, there should be a function for every different client.

First we have to get the corresponding client name for each client.

I hope the community will provide at least the values from

RegRead("HKEY_CURRENT_USER\Software\Clients\Mail", "")

in this thread for each client.

If a community member could provide the code for the corresponding function, the better.

Alternatively you could use "Mail PassView" by Nir Sofer. However, MOST antivirus programs will make it as a hacker tool as it also shows passwords.

Might be an option, but I would prefer to solve it without external program.

The other problem is many computers have multiple Email address. How are you going to work out which is the right one?

In MS-Outlook, always the first entry is the default entry. Found it by trial.

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The functions for Microsoft Outlook, Outlook Express, Windows Life Mail, Mozilla Thunderbird and Pegasus Mail are complete.

If you have a different mail client, please run the following script and post the consol output here.

$sClient = RegRead("HKEY_CURRENT_USER\Software\Clients\Mail", "")
If @error Then $sClient = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\Mail", "")
$sclients = "Microsoft Outlook Express Windows Live Mail Mozilla Thunderbird Pegasus Mail eM Client"
If StringInStr($sclients, $sClient) Then
MsgBox(64, @LF & @LF & " ", " Your e-mail program is: >" & $sClient & "<" & @LF & @LF & "It is already included in the script. Thank you.", 0)
Else
ConsoleWrite(@LF & " My e-mail program is: >" & $sClient & "< " & @LF & @LF)
MsgBox(64, @LF & @LF & " ", " Your e-mail program is: >" & $sClient & "<" & @LF & @LF & " Please post the output to the forum thread, if not yet there. Thank you.", 0)
EndIf

Already done:

My e-mail program is: >Microsoft Outlook<

My e-mail program is: >Outlook Express<

My e-mail program is: >Windows Live Mail<

My e-mail program is: >Mozilla Thunderbird<

My e-mail program is: >Pegasus Mail<

My e-mail program is: >eM Client<

Thanks

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

The functions for Microsoft Outlook and Windows Live Mail are complete.

If you add Outlook Express I'd "guess" you've covered a majority of the users out there.

The ohter ones I've com in to contact with (decending order) Incredimail, Thunderbird... well that is about it. (I'll probably think of more later).

In fact if you look up "Mail Passview" it has a list of clients it can work with. BTW I agree that external programs can be/are a pain.

If I run into any others I'll let you know.

Good Luvk

John Morrison

Share this post


Link to post
Share on other sites

If you add Outlook Express I'd "guess" you've covered a majority of the users out there.

Outlook Express is now also completed.

First post updated.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

I've added your script to my onsite installer script. If it has any problems or brings up new clients I'll let you know.

John Morrison

Share this post


Link to post
Share on other sites

The functions for Microsoft Outlook, Outlook Express, Windows Life Mail, Mozilla Thunderbird and Pegasus Mail are now complete.

First post updated.


My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

I think the Outlook part is a bit more complex.

You can have multiple profiles of which you select one (or let it default) when you connect to Outlook (ObjCreate). Every profile can have multiple accounts (Exchange, IMAP, HTTP ...). At the moment you return the SMTPAddress from the last account. I would return an array containing all Accounts. For each account the array should contain UserName, SMTPAddress and AccountType.

This way the user can decide which address to use.

If you like I can post some code.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

At the moment you return the SMTPAddress from the last account.

@Water, thanks for your contribution.

Yes, you are right, there are more than one address.

But I need the default SMTP address for sending e-mails.

And this is the first address in the for ... in loop.

Therefore the exitloop after the first iteration.

It is my intention to pre-fill an input field in a registration form.

In 99% this is the good choice. If somebody wants another address,

he is free to overtype the proposed default.

To implement a dropdown list would be overkill in my opinion.

@all

I have another question.

Is it possible to extract this information without using ObjCreate() ?

ObjCreate is very slow if Outlook is not running.

I would prefer a method with regread() and analysing application data like with other mail clients.

Works now without ObjCreate().

And if you are using a mail-client not yet in my list, then please post your result here. See post #5

Thanks Exit

Edit: Typo

Edited by Exit

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Is it possible to extract this information without using ObjCreate() ?

ObjCreate is very slow if Outlook is not running.

Not that I know of.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

A couple of issues apepared....

Sometimes it will crash on system with outlook installed. I couldn't do any testing as they were customers computers and I was onsite with them looking over my shoulder. :(

However, I'd say a bit of error checkign around the outlook code would fix it.

Also on a system with Outlook installed but not configured it will start Outlook and ask to be set up. (ie Enter email/password etc)

Other than that it appears to be doing "mostly" what you want from teh testing I've been able to do. :)

Though a "drop down" with all addresses found would solve the problem when the main address is the "business" address and the "Address they want to use" is one of the others. Just me 2c worth.

John Morrison

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

I've enhanced the Outlook code a bit so the function tries to connect to a running instance of Outlook. If the function has to start Outlook it is closed upon completion of the function.

; Code removed - was buggy. Please check post #19 for a corrected version
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thanks water

I've added that to my program.

It still leaves the condition where outlook has been installed but not "initialised" (ie hasn't been run).

What happens is outlook starts and you have to go through all the questions telling it NOT to set up an email account.

Is there any way of checking if outlook has had it's first run?

Thanks

John Morrison

Share this post


Link to post
Share on other sites

I've enhanced the Outlook code a bit so the function tries to connect to a running instance of Outlook. If the function has to start Outlook it is closed upon completion of the function.

Sorry but there is something wrong with the code. On my machine if I have outlook running it will shut it down. Outlook 2007

The wife is on my back to go "shopping" :( so I haven't had time to test whats hapopening. Sorry.

Share this post


Link to post
Share on other sites

Thanks water

I've added that to my program.

It still leaves the condition where outlook has been installed but not "initialised" (ie hasn't been run).

What happens is outlook starts and you have to go through all the questions telling it NOT to set up an email account.

Is there any way of checking if outlook has had it's first run?

Thanks

John Morrison

The only solution I can think of:
  • On a system where Outlook hasn't been "initialized" save the registry to a file
  • Start Outlook and enter the configuration data
  • Save the registry and compare it with the backup you saved in step one
Some registry keys where the profile is saved should be shown.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Sorry but there is something wrong with the code. On my machine if I have outlook running it will shut it down. Outlook 2007

The wife is on my back to go "shopping" :( so I haven't had time to test whats hapopening. Sorry.

Will do some more testing and come back as soon as I have a solution.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This code should work:

Func _Get_Microsoft_Outlook_Account()
    Local $bCreated = False
    Local $sAccount = "not found"
    Local $oClient = ObjGet("", "Outlook.Application") ; Try to connect to a running instance
    If @error Then
        $oClient = ObjCreate("Outlook.Application") ; No instance was running, start Outlook
        $bCreated = True
    EndIf
    If Not @error Then
        For $oAccount In $oClient.Session.Accounts
            $sAccount = $oAccount.SMTPAddress
            ExitLoop
        Next
    EndIf
    If $bCreated Then ; If Outlook has been started by this function, logoff and close Outlook
        $oClient.Session.Logoff
        $oClient.Application.Quit
        $oClient.Quit
        $oClient = 0
    EndIf
    Return $sAccount
EndFunc   ;==>_Get_Microsoft_Outlook_Account

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0