Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'incoming mail server' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
incoming mail server
Authored by: liedra on Jan 20, '03 05:52:05PM

How would you change this Applescript to switch the incoming mail server?

Thanks,
- liedra



[ Reply to This | # ]
incoming mail server
Authored by: haironfire on Jan 20, '03 07:44:44PM

If you have a POP mail account, just change the references to 'smtp' server in the original post to 'pop' server (without the quotes). Then change the server addresses to suit your situation.

That should do it.



[ Reply to This | # ]
incoming mail server
Authored by: liedra on Jan 21, '03 03:03:38AM

Nope! That didn't work. (Also I use IMAP, not POP, but the same should apply with POP).
To give you a little bit of background, I have a linux imap server running on the internal network at home, and a port forward through a linux proxy server that forwards my IMAP from outside the network. For some unrelated reason, I haven't been able to access the server from the one outside address, so I need something like this.
Here's my script (after hunting through the sample applescripts that work with Mail.app) NOTE: *should* work with POP too. But I don't have POP so I can't test it. YMMV, use at your own risk :-)

on run
set myResult to display dialog "Where are you?" buttons {"Home", "Outside"}
tell application "Mail"
if the button returned of myResult is "Outside" then
set server name of account "Default" to "outside.domain"
else
set server name of account "Default" to "internal.server"
end if
end tell
end run

(bah, tried to add in whitespace there but it didn't really work. it's basically the same formatting as the one on the original comment, just change the "set server" lines (and I cut out a bit of the other unnecessary stuff)).



[ Reply to This | # ]
incoming mail server
Authored by: haironfire on Jan 21, '03 07:38:20PM

My previous comments pertained to using the script for Entourage. Apparently, Mail uses a different set of naming conventions. Open Script Editor, the open the dictionary for Mail to be sure.



[ Reply to This | # ]
incoming mail server
Authored by: shreddiez on Jan 21, '03 03:51:07PM
Based on mattw's smtp server change, here's my script for pop server change, which also changes the port. The main differnce is that the applescript parses the settings to spilt up the server and port, then also sets the port using "set server port", but not "set port" as the Mail dictionary would have you believe :/
#!/usr/bin/perl -w use strict; # The Network Location name to POP server hostname mapping: my $pop_for_location = { Home" => "popserver.domain.com:110", "Uni" => "localhost:1110" }; # These are the account names to change my $accounts_to_change = [ "Default" ]; my $location = &get_location_from_scutil() || ""; unless(exists $pop_for_location->{$location}) { die "The location is unknown"; } my $le = "r"; open(APPLESCRIPT, "| osascript"); while(my $line = ) { chomp $line; if($line =~ m/property/) { if($line =~ m/%popserver%/) { my $newserver = '"' . $pop_for_location->{$location} . '"'; $line =~ s/%popserver%/$newserver/; } elsif($line =~ m/%accounts%/) { my $account_string = '"'. join('","', @{$accounts_to_change}) .'"'; $line =~ s/%accounts%/$account_string/; } } print APPLESCRIPT $line, $le; } close(APPLESCRIPT); sub get_location_from_scutil { my @scutil = `scutil /dev/null open show Setup:/ close end_scutil`; my @matches = map { m/UserDefinedName : (.*)/ } @scutil; if(@matches == 1) { return $matches[0]; } else { return undef; } } __DATA__ property newPOPAddress : %popserver% property accountsToChange : {%accounts%} set theDelimiter to AppleScript's text item delimiters set AppleScript's text item delimiters to ":" set the item_list to every text item of newPOPAddress set newPOPServer to item 1 of item_list set newPOPPort to item 2 of item_list as integer set AppleScript's text item delimiters to theDelimiter on weWantToChangeThisAccount(theAccount) set theResult to false --set theAccountName to name of theAccount --display dialog "this is " & theAccountName repeat with eachAccount in accountsToChange if (name of theAccount is equal to eachAccount as string) then set theResult to true end if end repeat return theResult end weWantToChangeThisAccount on theAccountAlreadyHasThisServer(CurrentServer, newServer) set theResult to false if (CurrentServer as string is equal to newServer as string) then set theResult to true end if return theResult end theAccountAlreadyHasThisServer set anAccountWasUpdated to "no" --if (theSMTPServer is not equal to false) then tell application "Mail" set everyAccount to every account repeat with eachAccount in everyAccount if (my weWantToChangeThisAccount(eachAccount)) then set currentPOPServer to server name of eachAccount if (my theAccountAlreadyHasThisServer(currentPOPServer, newPOPServer)) then -- do nothing else set server name of eachAccount to newPOPServer set server port of eachAccount to newPOPPort --display dialog "change " & name of eachAccount & " to " & name of theSMTPServer set anAccountWasUpdated to name of eachAccount end if end if end repeat end tell --end if return anAccountWasUpdated


[ Reply to This | # ]