Send automatic email message?

Hi, I just released my first Mac OS X app which keeps track of the batteries in your wireless devices and offers an estimate of when they'll die. A user claims to be from the IT department of a school and he'd like to install the app on all the school's computers. He'd like it if the app would automatically send him an email when it estimates the batteries will die within a week.

I know that I can open a URL to start mail and have a message and address already filled out, but how can I go a bit further and have it compose the message, address it, and send it automatically?

1 - How do I add that code to my app? All of my files right now are written in C and/or Obj-C, how would I go about adding Python code to some of my files?

2 - What would be the best way to minimize how much the user has to set up? Ideally, the user should just get several conditions under which they want to receive emails, and to set where the email should be sent. My understanding is that I'll also need to have a server or something from which to send the mail and an address for it to be sent from. That kind of crap is too complicated to set up... I don't want to deal with it, and I don't want my users to have to deal with it. Is there some way I can either
a - Find an account already set up to send mail on the computer and send mail from that or
b - Set up a free Yahoo! or Google mail account and just have my program send mail from that account (the greatest idea from a security standpoint, maybe not, but it would work and be easy to set up, correct?)

1 - How do I add that code to my app? All of my files right now are written in C and/or Obj-C, how would I go about adding Python code to some of my files?

Click to expand...

Using that python code is still going to require the user to input their mail server, username, password, etc.

Quote

2 - What would be the best way to minimize how much the user has to set up? Ideally, the user should just get several conditions under which they want to receive emails, and to set where the email should be sent. My understanding is that I'll also need to have a server or something from which to send the mail and an address for it to be sent from. That kind of crap is too complicated to set up... I don't want to deal with it, and I don't want my users to have to deal with it.

Click to expand...

If I were doing this, I would have a server or shared hosting account with a WebService setup. The app could send an email request to the WebService, and the mail would come from the server.

Quote

a - Find an account already set up to send mail on the computer and send mail from that or

Click to expand...

You can certainly send an email through the users default mail app, but I don't think you will be able to pull the credentials out. Also, what happens if those workstations don't have email accounts setup?

Quote

b - Set up a free Yahoo! or Google mail account and just have my program send mail from that account (the greatest idea from a security standpoint, maybe not, but it would work and be easy to set up, correct?)

Click to expand...

You could certainly do that, but you will likely expose your email account login credentials inadvertently. Try looking into the "Yahoo Mail Web Service" for a better solution.

If you, for example, send all emails to the same SMTP server (say the same gmail server) you would need the gmail username and password stored in the app. This has huge security implications.

I would think for IT guys who want email notifications, allow them to set an SMPT server, a From address, a To address, and possibly a subject. That would mean you could code your email to be sent to whatever SMTP server the IT guy wants, and having the ability to set the To, From and Subject headers would allow the the IT guy to craft whatever rules work for the IT guy's workflow.

In regards to actually sending an email, AFAIK, the Cocoa Objective-C APIs can't help you with this. If you want to you use a Python script as previously posted, you could include the Python script in your app's bundle and then use the popen function (see man 3 popen) to invoke the script, perhaps passing the actual email via standard in into the python script.

Mailcore is an Objective-C framework for iOS or OS X to send e-mail amongst other thing. This could better be integrated to your application than some Python script (or Perl script, or bash script using the system's mailx application, or whatever other external method you find).

I will also say you should simply provide the user with e-mail configuration options :

MacRumors attracts a broad audience
of both consumers and professionals interested in
the latest technologies and products. We also boast an active community focused on
purchasing decisions and technical aspects of the iPhone, iPod, iPad, and Mac platforms.