how to programmatically send email using objective C / cocoa - objective-c

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.

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.

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.

Related

How to write a program to automatically download a file from email

I have an email account (like gmail or something) that gets a daily email with a file attached to it that has some data in it. Is there a way to have a program check the email everyday, say at midnight or something, download that file, and store the contents into a SQL database?
I'm familiar with Java, JavaScript, PHP, HTML, and Python. Is there a way to do this using what I already know, or would it require some other technology?
I like to use Python for this kind of tasks, it's fast and minimalistic.
You can access mails using POP3 or IMAP protocol. Python contains modules to work with them: poplib and imaplib. POP3 is simpler, I advice to use it if you need just download mails and delete them after that.
IMAP is more advanced. Each message has it's own UID, that identifies messages. New messages have greater UID then old one, so every time you run downloading, you just need to store somewhere (in file, database) the greatest UID of messages you processed and use it to find newer messages when you will run downloading next time. See here example of working with IMAP from Python.
To schedule downloading each X hours, you can choose from these options:
Write application that download new messages, then sleep using sleep() function in infinite loop.
Write application that just download new messages and finish its work. Schedule its runs externally using Cron tool.
I developed such a solution in C# with Pop3client, don't know if it is the best though.
Here is an example doing it in Java:
pop3-client tutorial

Using URL Link To Send Params To VB.NET App

What I am looking for is using a URL link such as "MyApp://param=value" or "MyApp://mysite.com/?params=value" to open my application and read the params using GET. I do not want to use the click once method to do this, because I want the application to load up without the starting up bar at the topleft. I know it could be done but I could not find anywhere to do it at. You can see an example used over at curse.com where they use a link like "curse://curse.com/?etc=etc" to launch their app and download the item. Another example is with Ventrilo where you can use "ventrillo://etc" links to start vent and connect to a server. The reason I want this is because I plan to use it to give my customers a way to give their clients a way to connect to their servers with my software using a simple URL.
Since the question is about VB.NET, I’m assuming you are targeting Windows.
In that case, this can be done by registering a custom URL handler via the Windows registry.
Other operating systems have different ways of achieving this.

I want to build a web service that sends articles to my Kindle

Where do I start?
Is there some sort of API - or something I can get access to that allows me to format articles and send them to my kindle?
I would like to do this in Rails.
Edit: For further clarity, I guess my real question is, how does instapaper.com get articles from the web to my kindle? Can someone explain the technology behind that please and do they have access to the Kindle SDK?
Take a look at Calibre (http://calibre-ebook.com/), runs on Linux, Win and OS X. Python based, has a GUI and a command line, suitable for automation. You can do all kind of conversions to .mobi format as well as fetching news from website and packing it to .mobi, which can be then transferred via USB or sent to kindle email address. It's very simple to fetch & send articles automatically either on a server system with cron or leaving it running on desktop (with GUI) for non-technical users.
Calibre's command line tools are your best bet: http://calibre-ebook.com/user_manual/cli/ebook-convert.html is the call you would most likely be interested in.
I believe all Instapaper does is convert to .mobi format, and then send mail (with the .mobi file attached) to your specified Kindle email address (eg. foo#kindle.com).
If you're more interested in specifics, Marco (Instapaper's author) tends to be very forthcoming when people ask him technical questions. His Twitter account is #marcoarment.
Check out this ruby gem, it seems to do what you want:
https://github.com/29decibel/kindler

Emailing an image from an application

What's the best way of sending an email with an image from the application to the Mail.app for someone to send to any contact they like?
For example, in my app (iMood), you can select a 'mood', I'd like the user to be able to email this to a friend for example, by using a button in the navigation bar.
I can easily create the button etc. but just need to know a way to enable the user to send the image (ie. image.png) from the project to Mail.app as maybe an attachment or a picture in the email.
Thanks in advance.
This question has been answered many times and in many different forms.
Short answer: you can't. There is no API that allows you access to Mail attachments, and Apple's implementation of the mail URL scheme does not support attachments either.
To accomplish this, you have a couple of very unattractive options:
1) Build-in your own SMTP client. There are some Open Source libraries that are working toward this, but it's still a pain
2) Send the image to a third part server (yours) and compose and send the mail from there. Users probably won't like the possibility you collecting email addresses for nefarious purposes.
In your case, the best thing to do is save the image to the Photo Library. From there, users can send email with the photo.
If you'd like to see Apple enable email attachments, please file a request.

Set instant messenger display message programmatically

Would a script that sets display messages for instant messengers be simple or complex? After some searching, there doesn't seem to be any information about this at all.
For the sake of an example, if I had a text file of quotations, would it be possible to have the google talk display message change to a different quotation hourly?
Depends on which client you're using. As far as I know, Google's client doesn't offer any interface for plugins, but the open source instant messenger Pidgin does. I think there already is a plugin for what you want to do, but you can write your own using the documentation and examples they give you.
The complexity of writing something like this is based on how much C or Perl you know, since you can program in either of those for Pidgin. Reading code from other people's plugins, you should be able to figure out the Pidgin API.
You can use Kik API to programmatically send rich content and files between mobile applications. It is available for iPhone and Android platforms and takes only about 5 lines of code to integrate into your app. There is more info at the API website: http://www.kik.com/dev
Disclaimer: I'm on of the developers behind Kik API :)