Scripting GMail setup

Further to my previous post, I have made some good progress but the script still does not work completely.

I think the problem can be narrowed down to the second part of the following section:


tell application "Mail"
	make new pop account with properties {name:theAccountName, user name:theUsername & "@gmail.com", server name:"pop.gmail.com", password:thePassword, full name:theFullName, email addresses:{theUsername & "@gmail.com"}, port:995, uses ssl:true}
	make new smtp server with properties {password:thePassword, authentication:password, user name:theUsername & "@gmail.com", port:587, server name:"smtp.gmail.com", uses ssl:true}
end tell


tell application "Mail" to set smtp server of account theAccountName to smtp server "smtp.gmail.com"

pop server settings are fine and I can retrieve mail from GMail server all right now but I can’t find a way to setup the smtp server properly that is, adding password authentication and username + password.

I am slowly running out of ideas after having tried many different options. :frowning:
What am I doing wrong here?

Thanks in advance

/P

Not many seem to find this topic of much interest, nevertheless, I keep trying… :smiley:

I have made some additional progress and I am able to pass all necessary info to the new smtp server.
Here is how:


tell application "Mail"
	set theNewAccount to make new pop account with properties {name:theAccountName, user name:theUsername & "@gmail.com", server name:"pop.gmail.com", password:thePassword, full name:theFullName, email addresses:{theUsername & "@gmail.com"}, port:995, uses ssl:true}
	
       set theSMTPServer to make new smtp server with properties {server name:smtpServerName, user name:theUsername & "@gmail.com"}
	tell theSMTPServer
		set port to 587
		set uses ssl to true
		set authentication to password
	end tell
	
	set smtp server of account theAccountName to theSMTPServer
end tell

The above script creates the smtp server with the right settings however, from the last statement I get the following error message


So I am stuck at very last and final step, that is, selecting the newly created smtp server for the new account.
Everything else works fine.

Any ideas?

/P

ciao,

have you checked your messages?

I just did, thank you.

it looks like we are getting to the same conclusions.

However, still that final little step missing… :-\

I hope that I am not covering something you already figured out…

When I ask mail to list the names of its SMTP servers, like this:

tell application "Mail" to get the name of every smtp server

I get a list where each entry looks like “servername:username”. But the object returned from make new smtp server … seems only to be identified by the server name (no suffixed colon and username according to the event log output). I guess when that object (in theSMTPServer) is re-used later to attach to an account, Mail does not recognize it. But, in my testing, if I add the colon and the username, and ask for an smtp server by name, Mail is able to find it and attach it to the account:

tell application "Mail"
	-- Original code here

	-- Although the commented-out command seems logical, this one seems to actually work.
	set smtp server of account theAccountName to smtp server (smtpServerName & ":" & theUsername & "@gmail.com")
	--set smtp server of account theAccountName to theSMTPServer
end tell

Tested against Mail.app Version 2.1 (752/752.2)

Model: iBook G4 933
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Thanks a ton Chrys,
your are spot on, it works like a charm now. :slight_smile:

Should you be interested in the complete source code, please let me know.

/P