I want to parse mails that are send to an IMAP mailbox from my Grails application.
I tried this plugin: https://github.com/IntelliGrape/Grails-Mail-Watcher-Plugin but it does not provide all the functionality I need.
Edit: I need to get the following information from my inbox:
the number of mails
the number of unread mails
the number of read mails
a way to iterate over each mail
I need from the mail:
sender
receiver
subject
date
mail body
mail attachments
mail attachment types
if it is html or plain text mail
How can I read the mails and get the sender, subject, body and attachments?
as i'm not aware of any particular plugin, other the one you already mentioned, you could use the Java Mail API directly. One example of this usage can be found here. The other opportunity is, that you could either extend this plugin (the entry point should be here). The plugin uses the Java Mail API internally as well.
Related
My intranet web application (written in C#/ASP.Net MVC) sends email notifications in certain situations. I would like to intercept replies to such emails and perform actions based on the content of such replies.
I have no preference for scripting language - it could be Powershell, Python, VBA, anything - as long as I can parse the subject and body of the email, I can then alter the database of my web application through this script and pick up changes with an automated task, but I really have no clue where to start. I would be really grateful if someone could point me in the right direction.
QUESTION
How can I intercept emails sent to the Outlook server and perform action based on the content of such emails?
It sounds like you need an inbound email parsing service. I've worked with the one from SendGrid and it will catch any replies to a specific email address, and then post the email contents to an action on a controller in your MVC app. This will give you access to the full email contents and you can process it as needed.
See Setting up Inbound Parse
With my rails application, I'm supposed to provide following features:
There a limited number of users interacting with my system (in order of 10 to 20)
Like any normal mail client users should be able to have an inbox page showing received message, response to individual email and etc....
The mail client part cannot be an external application, they want everything packaged into a single application!
Normally These emails should be stored for future use
In order to send a receive email, we do not need to setup a mail server. They will provide the server and we will fetch the message with POP3 or something else. Same goes for sending emails.
The application itself often needs to look into these message as well, so it should be able to access corresponding email objects.
Separate part of these applications can be handled with individual gems such as Mailman, ActionMailer, and etc...
But what would be your suggestions to get this done?
I suggestion customizing an open source solution according to your needs. This is a gem/project that you should look at https://github.com/mailboxer/mailboxer It has all the features that you mentioned and its straightforward in its customizations.
I want an E-Mail to be sent using a background process whenever an Invite was generated.
What I currently have is this approach: The Invite model has the method send_mail, which sends an E-Mail using the Mandrill API and gem. It also has the method queue_mail adds InviteMailer with the invite's ID to the queue using Resque.
However… Since I'm having sort of a really hard time writing specs for this, I assume this might not be the best approach to send mails.
What I mainly want and need to test:
was the mail added to the queue?
is InviteMailer working properly?
does the mail contain the correct vital information?
Vital informations are: sent to the correct person, contains a link to a specific site and some specific data/text; also I'm not sure how to get the current host to the link.
I don't think this is a rare thing to do, so I wonder what the best practices are.
My testing environment: rspec, capybara, factory girl. I already added VCR, to cache the API-request.
You can use Mailcatcher to fake your mail server, and check received mail via web API:
Features
Catches all mail and stores it for display.
Shows HTML, Plain Text and Source version of messages, as applicable.
Rewrites HTML enabling display of embedded, inline images/etc and open links in a new window. (currently very basic)
Can send HTML for analysis by Fractal.
Lists attachments and allows separate downloading of parts.
Download original email to view in your native mail client(s).
Command line options to override the default SMTP/HTTP IP and port settings.
Mail appears instantly if your browser supports WebSockets, otherwise updates every thirty seconds.
Growl notifications when you receive a new message.
Runs as a daemon run in the background.
Sendmail-analogue command, catchmail, makes using mailcatcher from PHP a lot easier.
Written super-simply in EventMachine, easy to dig in and change.
How
gem install mailcatcher
mailcatcher
Go to http://localhost:1080/
Send mail through smtp://localhost:1025
API
A fairly RESTful URL schema means you can download a list of messages
in JSON from /messages, each message's metadata with
/messages/:id.json, and then the pertinent parts with
/messages/:id.html and /messages/:id.plain for the default HTML
and plain text version, /messages/:id/:cid for individual
attachments by CID, or the whole message with /messages/:id.source.
What I would like to accomplish is for a user to be able to send an email to a designated email address. Then once that email has been obtained, run a script that parses the body section of the email and carries out various tasks with the information provided in the email
(The data coming in from the email will be structured in an xml type format).
In my mind this seems like a simple task to accomplish but I'm not all that familiar with the inner workings of email. My questions are:
How will I know once an email has been obtained from the sender so that it can be processed?
How can I use php to obtain the text found in the email?
If you have PHP running on your mail server, then it's possible to pipe incoming mail to a PHP script. Then, your PHP script can parse the body of each incoming message as it arrives. See http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/ for more info.
I agree with the other responses, that piping to a php application should be your first option (if the mail server and php are the same)
Otherwise if you have an external mail server you will need to poll the email address at regular intervals and check for new emails.
Extracting plain text body from an email message is not too hard, but getting to attachments can be a pain sometimes.
You will need to use a cronjob to trigger your script at regular intervals
To fetch the email from the server and parse it, I have used the php IMAP functions
http://php.net/manual/en/book.imap.php
You can also use 3rd party services like MandrillApp which will receive the message, break it into parts, and call your application via a webhook.
http://help.mandrill.com/entries/21699367-Inbound-Email-Processing-Overview
Right now my app sends out email notifications. I'd like to allow the user to reply directly to the email, which then gets ingested by my app and inserted into the database.
Are there any Rails gems, services, tutorials that can point me in the right direction.
Also, probably need to make the reply-to email have a UID, replyto--UID#domain.com, so I don't have to rely on the from (sender).
What do you think?
Thanks
A few good articles to get you started:
http://railstips.org/blog/archives/2008/10/27/using-gmail-with-imap-to-receive-email-in-rails/
http://jasonseifer.com/2009/04/24/receving-email-with-rails
We have a free service that posts incoming email to a url of your application (same as sendgrid API):
http://www.smtp2web.com
You can also use the mailman gem if you want to poll for the email at regular intervals:
https://github.com/titanous/mailman
As far as the 'replyto--UID#domain.com' kind of email addresses are concerned, you will have to create a catch-all address for your domain (it is better if you use a obscure subdomain, as it would reduce the amount of spam) which forwards all such email to a given mailbox(say notifications#domain.com).
I would highly recommend using CloudMailin for the same.
It provides you a receiving email address, which you can add as a reply-to header in your mail.
About the unique UID, for tracking each reply in context of the sent email, you could generate a random string, and modify your reply-to header as "[email provided by cloudmailin]+[your random string]"
You'd need to look at configuring your sendmail/postfix to accept incoming mail first off ( if you're using unix based server ).
Heres a good article:
http://jasonseifer.com/2009/04/24/receving-email-with-rails
You can use Sendgrid to parse incoming email and have it send along to your app via a web-post.
This is a decent tutorial (heroku focused)
Or you can view Sendgrid's ParseAPI to see how to integrate.