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


Click here to return to the 'An AppleScript to switch Mail's SMTP servers' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to switch Mail's SMTP servers
Authored by: soj on Apr 19, '06 07:54:52PM
(n00b alert triggered)

Hi everyone,

I thought I'd be a smart-arse and modify liedra's code to change both the incoming and outgoing servers at once:


on run
	set myResult to display dialog "Choose profile to apply:" buttons {"Work", "Dial-up"}
	tell application "Mail"
		if the button returned of myResult is "Work" then
			set server name of account "myaccount" to "IP1.xx.xxx.xxx"
			set smtp server of account "myaccount" to smtp server "IP1.xx.xxx.xxx"
		else
			set server name of account "myaccount" to "mail.isp.com.au"
			set smtp server of account "myaccount" to smtp server "mail.isp.com.au"
		end if
	end tell
end run

... which seemed to work fine except for the strange problem that when I quit out of Mail after using the script to change server settings and restart the program, all my mail in the Inbox and Sent Mail folders will have vanished. Thankfully, they reappear after executing Mailbox>Rebuild from the drop-down menu.

The problem only occurs when the script is used to change servers from what they were before the script is run.
What doesn't cause the problem:

- changing servers manually (using the same server names)
- using the script but not changing the servers i.e. ‘re-applying' the existing settings, e.g. selecting ‘Work' when the Work settings are already in effect
- using the script to change servers to the alternate configuration, then using the script to change it back to the original configuration without quitting Mail, e.g. from ‘Work' to ‘Dial-Up' and then back to ‘Work' again. After doing this, when Mail has been quitted and restarted again, things are fine.

Any ideas?

[ Reply to This | # ]