views:

396

answers:

3

Hi I am new to MAC OS development and I want to send an email programmatically trough an application, but without using Mail app like in SBSendEmail from apple's site. I dont want to attach any attachments, just a plain text email. What is the best and easiest way to do this? is it possible to use the basic functionality from SBSendEmail and automate the last step of sending mail through MAil app? Is there no easy way just like in C# to create a mail object and just send it? Thank you.

+2  A: 

Here's a discussion on the Apple support forums that should help.

Robert Greiner
Hi thank for reply..but I have already gone through this discussion, they have mentioned same SBSendEmail application and I tried using open source C++ library, I got completely messed up as I am new to MAC OS X and X code, I completely lost track of how to reference and integrate the C++ library with objective C. is there any reference documentation that I can use?
Aniket
did you check out the readme? http://developer.apple.com/mac/library/samplecode/SBSendEmail/Listings/ReadMe_txt.html
Robert Greiner
Note that SBSendEmail works by telling Apple's Mail application to send the email. It cannot work if the user has not configured Mail to send mail (most probably because they prefer Thunderbird and set that up straight away without even opening Mail).
Peter Hosey
yes as peter said, I dont want to use mail application to send an email, as it is not the best way, I want to automate the process and use something like smtpclient and mailMessage classes from C#..any idea about it?
Aniket
A: 

There's no way to do this in pure Cocoa, except to use one of the three or four email libraries available (Pantomime is one I know of off the top of my head). The main problem with all of these is that they're designed for implementing a full email client, not just sending email, so they're probably more heavyweight than you need.

For Growl's MailMe display, I wrote a command-line mail-sending tool in Python. The Xcode project bundles this into the MailMe display plug-in bundle, and MailMe runs the tool using NSTask, passing the SMTP info it finds in the user's Mail preferences. Growl is also open source, so you can read the source to the MailMe display.

Things that won't work:

  • The Message framework, which has no public API in 64-bit.
  • The mail(1) tool, which requires the user to have the local SMTP server running (simple-mailer uses another SMTP server, whose name you pass in on the command line).

Note that MailMe currently does not understand how to look up MobileMe passwords, so it isn't yet able to send using MobileMe accounts. If you amend the code to do this, we'd appreciate a patch!

Another patch opportunity is that MailMe currently only looks in Mail's preferences for mail-sending settings. It could look in other clients' preferences, but does not yet know how to do that. If anyone who uses Thunderbird would like this capability, again, we'd appreciate a patch.

Peter Hosey
SMTP is a very simple protocol, if you know the SMTP server it may be easier to communicate with it directly using sockets. I did this as an exercise once and was amazed at how simple it is to send emails.
dreamlax
can u please explain this with some detail?
Aniket
A: 

I would suggest you make use of /usr/lib/sendmail if present. Open a pipe to /usr/lib/sendmail and send the mail on stdin. This should be available the OS.

eneville
sendmail will try to send it through the local SMTP server. On any Mac OS X client machine, the local SMTP server isn't running, so the mail won't actually get sent. Also, it's /usr/sbin/sendmail; /usr/lib is for libraries.
Peter Hosey
/usr/lib/sendmail is the defacto location for sendmail, although it may appear unconventional. Its far more reliable to hand the mail to a local MTA rather than attempt SMTP delivery at that time. The system admin should configure sendmail or ssmtp or something similar to do the delivery, it doesn't have to be a full blown mailer, just something that can queue.
eneville