After downloading a mail through IMAP, before parsing I want to check if its spam! - spam

I have a ticket system in PHP. People report tickets over email. A mail parser connects to the mailbox using IMAP, downloads the email and parses it to create a ticket which can be viewed/updated over the web interface.
Now I want my application to check if the downloaded mail is a spam before it creates a ticket out of the mail. So I thought of integrating spamassassin. The docs say, it can be implemented as a proxy. I am not sure how to do this.
Basically what I want is a way to pass the email as a string to the spamassassin perl script which validates the mail?
Has anybody done something similar before. Can you suggest some other related good tools?
Edit: I am using Google apps mail-server. So its not an option to integrate SpamAssassin at the MTA or MDA stage.

Can you install spamassassin in your webserver? because spamassassin supports pipes. you can make a syscall from php to use spamassassin from command line and parse the answer. Or you can use this http://ppadron.blog.br/2010/05/04/php-api-to-spamassassin-spamd-protocol/ Or you can use a reliable antispam service for your domain.

Related

How to check a email in linux server automatically?

I have a Ubuntu 14 server, I have to assign a email account to this server, when some person write a email to this account, the server have to open this mail automatically, and check if there are a specific information, if yes some thing happen.
I suppose that the email are stored in a data base o something like that, but I not have any idea how to start.
Any Idea
First you should get confident how mail systems work in general on linux machines. A good start would be to dig into the linux documentation project, particularly the linux electronic mail administrator HOWTO, chapter 3 (how electronic mail works): http://www.tldp.org/HOWTO/Mail-Administrator-HOWTO.html#toc3
Then, you can decide to which extent you want to set up your email account on the ubuntu server (full smtp server, only mail client etc).
As #arkascha mentions in his comment, the least painful way would be to use an existing mail server and fetch mail from there. With scripts, appropriate actions can be taken once a mail has been received.
If I have correctly understood your question, what you need is a mail alias to a command.
The following may depend on the actual mail server that you use, at least it is relevant for good old sendmail, and postfix. The mail system can use an alias database (normally the file /etc/aliases) but can be hashed into a binary version. This files can contains plain aliase that simply redirect a mail address to other mail addresses, and can also contain file aliases (the mail is appended to a local file) and program aliases.
In this last case (lines are like local_address: | /path/to/program), the program is started for each mail, and it receives the message through its standard input. Read the manual for your mail server for more detailed instructions.

trigger a .sh script when a specific subject email is received

Anyway, I have a script that I want to run whenever I receive an email on gmail. And if possible a subject specific email. is such a thing possible and if so, what programs do I need to allow it.
You can't instruct gmail to trigger an external script for you. I think you've got a few basic choices. In order of increasing difficulty and complexity:
1) Configure a gmail filter to deliver your desired messages to a special folder. Write a script to poll that folder, download (or delete or mark as read) messages it finds there, and then launch your local script. Set up a cron on your local machine to run the script every few minutes. You can poll the folder with IMAP or the GMAIL API. IMAP is probably easier. This will be tricky with shell, you're better of with Python, PHP, or similar.
2) Configure a gmail filter to forward your desired messages to an address on a mail server that you control. Use procmail or similar to intercept the incoming messages and launch your script.
3) Set up an account at Mailgun and configure the emails so they get delivered there directly. (Or forward from gmail as in #2.) Configure Mailgun to launch an API request when it receives messages. Build an API handler to receive the request. Launch your process from your API handler.
I have never done it, but I guess the first thing you should do is to take a look at the Google's Gmail API...
What is the Gmail API?
The Gmail API gives you flexible, RESTful access to the user's inbox,
with a natural interface to Threads, Messages, Labels, Drafts, and
History.
It seems to fit what you want - at least, without knowing the details of what you want to do.
The Gmail API can be used in a variety of different applications,
including, typically:
Read-only mail extraction, indexing, and backup
Label management
(add/remove labels)
Automated or programmatic message sending
You can use several programming languages - maybe the trick is using your programming language of choice to write a wrapper for the .sh script... I hope this helps!

sendmail: specify SMTP server and TLS options per message

I need to send emails form a script where the SMTP I want to send by varies per message. Using mailx, one may specify the SMTP server, TLS options, username, and password on the command line. However, I need to send embedded HTML emails (not as attachment), and mailx does not support that, according to various posts I've found and time spent pulling my hair out trying to get it to work. On the other hand, with sendmail I can send embedded HTML, but it seems the SMTP server options have to be in a config file, and I don't know how to override them from the command line. So how do I send embedded HTML while specifying custom SMTP options?
I gather you're looking for a low-level solution, but this is so straightforward in Python that I think it's worth exploring. There are several examples of literally exactly what you're trying to do right here in the documentation.
I also answered a similar question here.
Even if you're unfamiliar with Python, those docs pages pretty much spell out the whole program for you.

Is there any way to use (embed) Gmail - Yahoo on your website?

I'm not talking about something like cURLs or SMTP server
I have an stupid idea that instead of building a upload system, user can email for me with attach file.
So I think if gmail (or yahoo..) has an API to embed the SEND Mail page with a free account to my webpage so that all the user can use it?
Sorry for my bad English :D
You could either simply provide an email address and ask that people send emails to it with their attachment(s), or create a HTML form which allows users to upload a file which is processed by CGI. I use Uploadify on the front end, and a Perl CGI script to process the results.

Best Way To Receive Email Website

I am developing a website -- in the prototype stage, soon to be alpha. I will provide an email address to each account that allows the user to deposit stuff -- not a real email account, just an endpoint for sending things to the site. Many sites provide this kind of service nowadays. I think the first one I saw was Photobucket, which let's you send photos as email attachments.
My question is, what is the best way to implement this kind of service?
In my prototype, I have written a POP3 client which fetches all newly delivered mail (currently from a test Gmail account). My service processes each new mail and attachments, and immediately removes it from the email server.
I could certainly outsource to an email service with POP3 and be done with it. The problem is cost. Most services I have seen provide much more than I need, and they charge per account. I expect to have many accounts and low traffic volume.
So I'm leaning towards hosting email receipt myself. I am open to Windows or Linux. The code that processes incoming emails runs on Windows, but I have other services running on Linux. I have seen a number of open source and free email servers, such as hMailServer and MailEnable (Windows) and qmail, Postfix and exim (Linux).
I guess I have a slight preference towards Linux because of lower hosting costs, but if a Windows service can provide cleaner integration, that might be worth it. As far as features, I would like to have some spam filtering, but it's is not a huge priority. POP3 is adequate for retrieval, but a more direct API would be nice. I will need some kind of API for programmatically provisioning new accounts.
All suggestions are appreciated. Do you know how others implement this kind of service?
UPDATE: I ended up using hMailServer, which is a free mail server that runs on Windows. It seems to be quite mature and robust. It has a COM interop library which makes accessing emails, accounts, etc. from my .NET server app very easy indeed.
If you're going the host-your-own-email-server route, I would probably just use POSTFIX and pipe all your email to a PHP script, which processes the email.
Here's a quick'n dirty tutorial on setting up the email pipe if you're using cPanel:
http://kb.siteground.com/article/How_to_pipe_an_email_to_a_PHP_script.html
If not, here's how to do it:
http://answers.google.com/answers/threadview?id=562518
The bottom line is, you need to have an open SMTP connection to accept email. If you have your own server, then you can install a SMTP server on the machine. Usually, you have filesystem access to the location the email files are placed. Be sure to select a SMTP server that allows this, and that the email are in a format that you can parse.
Then, you can just monitor the file location for incoming emails.
If you can't pipe your emails (using the Postfix suggestion), and you don't have your own server (for example, on a shared hosting plan), then you will need to query a POP3 or IMAP mailbox server for your emails, and parse them accordingly.
I wanted to get emails in real time so I worked out my own solution with google app engine. I basically made a small dedicated google app engine app to receive and POST emails to my main site. That way I could avoid having to set up an email server.
You can check out Emailization (a little weekend project I did to do it for you), or you this small GAE app that should do the trick.
I kinda explained it more on another question.
Hope that helps!

Resources