How to check a email in linux server automatically? - linux

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.

Related

Setting up simple web application service and testing - Linux debian 10

I am doing my assignment given by the lecturer. On the title stated, my idea is about setting up a mail server on the server and we can send the email from the client, all the email is stored in the server virtual machine. Do my idea is correct on this title stated or any recommendations?
Sending mail is not that hard, especially just using (E)SMTP, tcp
text dialogs. Or you can use Linux mail commands.
Storing mail, either locally or accessing mail on a pop or imap server, poses
another set of challenges.
And of course, you need the HTML web pages as well as the services.
Attaching files can be another challenge, both uploading the files
and encoding them for inclusion in the mail.
JAVAScript can make some usual features of email clients easier, like sorting a list of emails in a folder or from a search by a column ascending or descending.
Searching email is an even bigger challenge!

Is it possible to create a catch-all email using postfix which accepts any email address and sends an email to an external address?

Some background and my challenge:
Background
I am using Magento 2.x using a virtual machine set-up which runs on Ubuntu 16.04
Challenge
My goal is to be able to test emails sent to me from the Magento application. In an ideal situation, I would not use an extension or third-party service (although a third-party SMTP server on the linux box could work).
To achieve my goal, I need to be able to register as a customer in the Magento application with any email address (fake or real) and have the email sent to the same external email address, no matter what.
What I've done so far
I've installed postfix
I've installed Magento using luma.com as the domain (and set up my hosts file accordingly on my host machine, etc.)
I've created a linux user account called "contact"
I've configured inet_interfaces in /etc/postfix/main.cf as loopback-only
I've set mydestination to $myhostname, localhost.$mydomain, $mydomain
I've configured Magento to send its store emails from contact#luma.com
I've set up an aliases file as the following:
postmaster: root
root: contact
contact: me#gmail.com
Then I ran newaliases As far as I recall, email sends fine with this setup. Hooray!
Next, the catch-all part. For this, I've tried loads of things, and none seem to work. From the reading I've done, I've tried the following:
In /etc/postfix/main.cf, I added the following:
virtual_alias_domains = luma.com
virtual_alias_maps = hash:/etc/postfix/virtual
Next, in /etc/postfix/virtual, I encountered my first problem. As far as I understand from the reading I've done, I'm supposed to use something like:
#example.com contact
This step apparently ensures that any email sent via postfix (e.g. from the Magento application) which uses an #example.com email address would be routed to the contact linux user I created above. Then, my thinking was that the system would use the alias I set up to ultimately send out that email from contact#luma.com (via the settings in Magento) through to the external address I set up in the aliases file. This approach would theoretically allow a user to register for an account with Magento using, say, joe#example.com, and then send the associated Welcome email to my external email address.
The issue with this is that I need the system to do this for any email, not just for emails ending in #example.com
Just for sake of completeness, I'll say that before asking this question, I was most recently researching how to achieve this part of the challenge using pcre tables. I've also tried configuring something using luser_relay, but both of these things are over my head at this point, so I'm lost.
My hope is that someone can offer some guidance as to whether I'm on the right path, where I may have missed something, and ultimately, offer some advice on whether my challenge can be solved and how I might go about solving it.
Thanks for reading.

Add unix user to postfix maillogs

I am using CentOS 6, and postfix mail server, from postfix mail log, I want to see which Linux user has sent specific email, is it possible? How can this be done?
I need this to prevent spam from our mailservers, by one of our users. I need to figure out which user, and what script.
Since you know which email you are looking for (you should know its ID from the message header), you can simply find it in postfix mail log located in /var/log/mail.log - just look for the message ID in the log.

How to access some email, and print a specific mail's message body?

I have an email address email_reports#coldmail.com, on which some reports are received daily. How can I access that mail through a terminal, find a specific mail that I need (say, check the headers or the body for string DEBUG: Daily Data Report), and print out it's body to a file in a single piped command? I have Ubuntu 12.04 LTS, and the standard mail command, as well as mutt. I've tried searching for such functionality online, but all I've managed to find is guides on how to set up various mail agents, but not to process emails in a script-like fashion.
See http://harrybailey.com/2009/02/send-or-pipe-an-email-to-a-php-script/ for an excellent article on how to pipe incoming mail to a script. This technique can be used to pipe incoming mail to just about any kind of script, be it php, perl, python, etc.

After downloading a mail through IMAP, before parsing I want to check if its 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.

Resources