Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 25, 2012, 11:05 AM   #1
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
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?
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 25, 2012, 11:42 AM   #2
danwilliams
macrumors member
 
Join Date: Sep 2008
Python has the smtplib that can automate the process.

Code:
import smtplib
emailServer = smtplib.SMTP('my.mail.server.address.com')
emailServer.sendmail("me@foo.com", ['you@foo.com'], "Hello world")
emailServer.quit()
Your app could call your python script that emails your battery low warning.

Last edited by danwilliams; Jan 25, 2012 at 11:44 AM. Reason: edit for clarification
danwilliams is offline   0 Reply With Quote
Old Jan 25, 2012, 05:00 PM   #3
ArtOfWarfare
Thread Starter
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
I don't know anything about Python... how do I use that code?

I guess to be more specific my questions are:

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?)
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 25, 2012, 05:18 PM   #4
phantax
macrumors member
 
Join Date: Feb 2009
Quote:
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?
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.
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
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?)
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.
phantax is offline   0 Reply With Quote
Old Jan 26, 2012, 03:09 AM   #5
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
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.

SORRY: I didn't see phantax's reply, some 10 hours before mine. My excuse, it's Australia Day, and I'm significantly altered appropriately.
jiminaus is offline   1 Reply With Quote
Old Jan 26, 2012, 05:39 AM   #6
KnightWRX
macrumors Pentium
 
KnightWRX's Avatar
 
Join Date: Jan 2009
Location: Quebec, Canada
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 :

- Username/password for authenticated SMTP
- SMTP server
- Display name
- From e-mail
- multiple To recipients
__________________
"What you leave behind is not what is engraved in stone monuments, but what is woven into the lives of others."
-- Pericles
KnightWRX is offline   0 Reply With Quote
Old Jan 26, 2012, 07:30 AM   #7
Jeremy1026
macrumors 68000
 
Join Date: Nov 2007
Set up a PHP script that gets the email to send to via POST. Send the POST method using your application containing the address to send to. Then use PHPs mail() function.
__________________
1026 Development
Jeremy1026 is offline   0 Reply With Quote
Old Jan 26, 2012, 05:41 PM   #8
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Wouldn't this be a good place to try and use Growl?

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Feb 5, 2012, 07:43 AM   #9
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: Richmond, VA
Quote:
Originally Posted by KnightWRX View Post
I will also say you should simply provide the user with e-mail configuration options :

- Username/password for authenticated SMTP
- SMTP server
- Display name
- From e-mail
- multiple To recipients
Your interface should also include a "send a test message" button so the user can verify the system is working.
__________________
How to ask good programming questions: Getting Answers
GorillaPaws is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
email won't send with url in message Rufmanj Mac Basics and Help 0 May 6, 2014 09:46 PM
iPhone: Unable to send and receive text message to email SamIam2 iOS 7 0 Mar 12, 2014 08:41 AM
Why do they give you the option to send a text message to someone's email address? TH55 iPhone 42 Dec 23, 2013 12:22 AM
Can't send email from other apps. New message box pops up then goes right back down. Leaping iPad Tips, Help and Troubleshooting 0 Apr 2, 2013 04:35 PM
Calendar app to send automatic emails activate iPad 0 Sep 29, 2012 06:48 PM

Forum Jump

All times are GMT -5. The time now is 11:35 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC