Problem scripting mail.app

Hi all,

So I wrote a backup script which, at the end, fires up Mail.app and has it send the backup log to various people. This was working fine until about 2 weeks ago, when it suddenly broke. Now it no longer sends the email, although if I go to the backup server and manually launch Mail.App, the email will get sent out (I guess it’s getting constructed property and getting queued but not getting sent).

Here’s what I’ve got (NOTE: I’ve changed the sending and receiving email addresses here for anonymity purposes):


if BackupSuccess is equal to true then
	set theSubject to "Backup succeeded on " & m & " " & d & " " & y
	set theBody to "The backup on " & m & " " & d & ", " & y & " succeeded and backed up roughly " & legibleSize & " GB of data."
else
	set theSubject to "Backup failed (at least partially) on " & m & " " & d & " " & y & "!"
	set theBody to "The backup run on " & m & " " & d & ", " & y & " failed.  Attached is the backup log."
	set theAttachment to POSIX path of log_target
end if
set theSender to "user1@domain.com"
set theName to "File Server"
set theAddress to "user2@domain.com"
tell application "Mail"
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody & return & return}
	tell newMessage
		set visible to true
		set sender to theSender
		make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
		if BackupSuccess is equal to false then
			tell content
				make new attachment with properties {file name:theAttachment} at after the last paragraph
			end tell
		end if
	end tell
	send newMessage
	delay 15
	quit
end tell

Anyone have any ideas to why this isn’t working? I realize the problem might be with mail.app itself (perhaps one of the OS X updates broke it) but I think the likelier culprit is the “send” Applescript command.

Thanks much!

Cheers,
John

Double check your outgoing mail server settings (SMTP) in the Mail.app preferences.
Has the name of your mail server changed?
Authentication /password / port changed?

We had this issue recently when one big company gobbled up another and changed our outgoing mail server. I could receive mail, but, all of a sudden we couldn’t send mail. Simple to fix in the Mail prefs.

None of our mail settings have changed, and indeed that wouldn’t explain why the message goes out the moment I manually fire up Mail.App. That’s the strange part. I would think that maybe Mail.App was shutting down before the “send” command was completed, but I have a 15-second pause in the script for that very purpose. I guess I can lengthen the pause, just in case perhaps Mail.App is having some significant delays in contacting the SMTP server.