Download mail using IMAP with fetchmail - email

I need to download all mail messages from a mail account with fetchmail.
When I try with POP3 I can download all mail correctly in this format:
[root#srv root]# ls /home/mail_import/MAIL_USER/new/
1453828024.7837_0.srv
1453828029.7843_0.srv
But pop3 protocol don't allow to choose a folder, so i need to use IMAP.
I cannot download the mails separately when using IMAP. I tried and I have a single file with all mails.
For example:
[root#srv home]# stat /home/mail_import/MAIL_USER/teste
File: ‘/home/mail_import/MAIL_USER/teste’
[root#srv home]# head /home/mail_import/MAIL_USER/teste
From root#SRV Tue Jan 26 18:56:31 2016
Return-path: <root#SRV >
Envelope-to: MAIL_USER#SRV
Delivery-date: Wed, 02 Dec 2015 15:47:00 -0500
I need to download all mails using imap in separate files like the pop3.
My .fetchmailrc is:
set bouncemail
set no spambounce
set softbounce
set properties ""
defaults:
antispam -1
batchlimit 100
poll DOMAIN with proto IMAP
user 'USER' there with password 'PASS' is 'MAIL' here
options keep fetchall ssl mda "/usr/bin/procmail -f %F -d %T";
folder INBOX
and my .procmailrc is:
MAILDIR=/home/mail_import/MAIL_ACCOUNT
DEFAULT=$MAILDIR/INBOX
LOGFILE=/var/log/procmail
LOCKFILE=$MAILDIR/.default.lock
VERBOSE=on
:0 fhw
|formail
#
## Any other rules the user wishes to either include with INCLUDERC,
## or hardcode into this file, would go here.
## --------------------------------------------------------------------------
## If we're here, the mail didn't match any other rules, so deliver normally.
:0:
$DEFAULT
## If that fails, report an error and throw the mail away.
EXITCODE=75
:0
/dev/null
There is some correct option to download the e-mail using IMAP separately equal POP3?

I don't see why you are using Procmail here at all. Just run Fetchmail and let it fetch your mail. Specify a destination folder in a suitable format, and go.
Whether or not email messages are separate files is not a feature of the protocol. It is a feature of the delivery program you use; if you choose to deliver to a file (Berkeley mbox format; what you are seeing here, with a From_ line at the beginning of every message) then all messages will be delivered to a single file. If you deliver to a folder (in maildir format, for example, with the new tmp cur subdirectories) you will get the result you are asking for. Just do whatever you did to get your POP3 messages into the maildir folder MAIL_USER, only using imap instead of pop3, and you are all set.
If you specifically want to do this in Procmail, change
DEFAULT=$MAILDIR/INBOX
to
DEFAULT=$MAILDIR/
But the entirety of your .procmailrc seems pointless. Why do you pipe stuff through formail? The actions you have simply duplicate Procmail's default behavior, with a couple of bugs. I think you could simplify both your own understanding and the process by figuring out how to have Fetchmail deliver the messages straight where you want them. (Not entirely sure whether it supports maildir, though; quick googling was inconclusive. Maybe don't specify an mda at all if that's how you made this happen with POP3.)

Related

Does Dovecot-LDA need the -f argument (and what is its purpose)?

Dovecot-LDA seems to deliver mail without the -f argument, and delivered mail is identical with and without it, however many setup guides include it in the delivery command. I'm frequently seeing error messages regarding invalid -f arguments, and I figure that removing it from my delivery command should fix this.
How does the -f argument change Dovecot-LDA's behaviour, and do I really need to provide it?
-f sets "envelope sender". It is email address used in SMTP protocol MAIL FROM: command to indicate where delivery failure notifications should be send.
AFAIK dovecot-lda does not use it itself but may be used by sieve filters.
AFAIK Most MTA/SMTP servers put envelope sender address in Return-Path: header before the final delivery (e.g. before passing the message to dovecot-lda).
My rule of thumb suggestion: Try to fix your problem.
IF it is hard to fix AND you do not use envelope sender in sieve scripts
THEN you may remove -f option from dovecot-lda command line parameters.

Recover email sended through exim?

lost some important data from my server and I know that data was sended via email. I have root access and I need to recover those emails.
I looked into exim logs and I have the email ID, but when I use a command like:
root#server [/var/spool/exim/msglog]# exim -Mvh 1ZfRwk-003bDf-JB
Failed to open input file for 1ZfRwk-003bDf-JB-H: No such file or directory.
Logs looks like:
2015-09-25 08:17:50 1ZfRwk-003bDf-JB <= info#myserver.com U=username P=local S=7453 id=20150925121750.117390002 ...... etc
I am running WHM under centOS
Is possible recover sended mails?
Any help would be appreciated.
No, You can not recover any mail which was send from your server. You can check your 1ZfRwk-003bDf-JB mail logs with the following command so that you can find out full logs of that mail.
grep 1ZfRwk-003bDf-JB /var/log/exim_mainlog

Debian - invoke external script from exim on receipt of emails

I am looking fopointers on the best approach to process incoming emails to a certain vhost and to call an external script with the email data as parameters - basically to allow email to be sent to a certain "private" email address at a host which then auto inserts something into that sites database. I currently have exim set up as the mail handler.
You have to follow exim single file configurations structure. In routers section write your own custom router that will deliver email to your desired php script. In transport section write your own custom transport that will ensure delivery to the desired script using curl. Just write the following configurations in your /etc/exim.cnf file:
############ROUTERS
runscript:
driver = accept
transport = run_script
unseen
no_expn
no_verify
############TRANSPORT
run_script:
debug_print = "T: run_script for $local_part#$domain"
driver = pipe
command = /home/bin/curl http://my.domain.com/mailTest.php --data-urlencode $original_local_part#$original_domain
Where mailTest.php will be your destined script.
Procmail is a good generic answer. If your needs are very specific, you could hook in your own script directly from your .forward (or Exim's corresponding construct -- can't remember exactly how it differs), but oftentimes, wrapping your own script inside a simple .procmailrc helps you avoid a bunch of iffy details of email delivery, and concentrate on the actual processing.
:0
' ^Subject: secretpassword adduser \/[A-Z]+
| echo "insert $MATCH into users" | mysql -d users

Cpanel Mail Query

I have a client whom's disk space has been taken up by mail. Is there away that I can delete all old emails that have been deleted/tml files. I do not want to loose the clients inbox emails.
To see the oldest emails/files you can use the following command:
ls -ltr /home/cpanel_user/mail/example.com/user_email/cur
Have a look at /home/cpanel_user/mail/example.com/user_email/
I think you should look on one of this folders:
new -> unread emails
cur -> e-mails that have already been read
.Trash
.Sent
Also you should use a du -h --max-depth=1 /home/cpanel_user/mail to see what folder use most of disk space.

Catchall Router on Exim does not work

I have setup a catchall router on exim (used as last router):
catchall:
driver = redirect
domains = +local_domains
data = ${lookup{*#$domain}lsearch{/etc/aliases}}
retry_use_local_part
This works perfectly when sending emails locally. However, if I login to my GMail account and send an email to whatever#mydomain.com, then I get an "Unrouteable Address".
Thank you for any hints to solve this issue.
In the system_aliases: section of the config file you already have a section which does the lookup in /etc/aliases.
Replace
data = ${lookup{$local_part}lsearch{/etc/aliases}}
with
data = ${lookup{$local_part}lsearch*#{/etc/aliases}}
and make sure you have *:catchall_username* in /etc/aliases
This works great for a single domain mail server which is already using /etc/aliases
For this router to work, make sure that
mydomain.com is in local_domains
there is an entry for *#mydomain.com in /etc/aliases
MX record for mydomain.com is pointing to the server, where you've
configured this
This is old as heck, but I didn't see a good answer posted and someone else might want to know the answer.
This post is geared towards Debian with in single configuration file mode. It should work on any Linux Exim4 install though. For the purpose of explaining things we’ll use test#example.com which is configured with the hostname mail.example.com. The system will have a real user called test and we want to create an alias for test called alias. So the end result will all email sent to alias#example.com forwarded to test#example.com without having to create the user alias on the system.
First we need to create a place to store all of the alias files:
mkdir /etc/exim/aliases.d
vim /etc/exim/aliases.d/mail.example.com
contents of the alias file for mail.example.com alias:test
vim /etc/exim/exim4.conf.template
Now look for the section system_aliases. Here you’ll see data = ${lookup{$local_part}lsearch{/etc/aliases}} or something similar. Change that to
data = ${lookup{$local_part}lsearch{/etc/exim4/aliases.d/$domain}}
Save the file and restart exim. The alias should now work. To add support for other domains just add more alias files in the aliases.d directory with the correct hostname.
I copied and pasted this from my blog:
0xeb.info