Overview:
These steps will try to configure the CentOs server to fetch the emails from gmail
and store it to the mail inbox of the local linux user malex. The mailbox can
be read using the program mailx.
CentOs 8 hostname: thermalite.localdomain
Linux user: malex
Gmail Accout: mygmail@gmail.com
1 2 3 4 5 6 7 | [root@thermalite ~]# yum install fetchmail Last metadata expiration check: 2:55:51 ago on Mon 10 Aug 2020 12:13:12 PM EDT. Package fetchmail-6.3.26-19.el8.x86_64 is already installed. Dependencies resolved. Nothing to do. Complete! [root@thermalite ~]# |
# 1. create a ~/.fetchmailrc to set the user account config
1 2 | [malex@thermalite ~]$ ls -l ~/.fetchmailrc -rw-------. 1 malex malex 222 Aug 10 13:22 /home/malex/.fetchmailrc |
# 2. View content of the ~/.fetchmailrc file, chmod to 600
1 2 3 4 5 6 7 8 9 10 | [malex@thermalite ~]$ cat /home/malex/.fetchmailrc # set username set postmaster "malex" # set polling time (5 minutes) set daemon 300 poll imap.gmail.com with proto IMAP user 'mygmail@gmail.com' there with password 'passfromapppasswords' is malex here options ssl [malex@thermalite ~]$ |
# 3. configuration for the fetchmail in /etc
Note: The password is not the actual password but the app password to by-pass 2-Factor authentication. See https://support.google.com/accounts/answer/185833?hl=en
1 2 3 4 5 6 7 8 9 | [root@thermalite ~]# cat /etc/fetchmailrc.example # set username set postmaster "malex" # set polling time (5 minutes) set daemon 300 poll imap.gmail.com with proto IMAP user 'mygmail@gmail.com' there with password 'passfromapppasswords' is malex here options ssl [root@thermalite ~]# |
# 4. restart fetchmail service
1 | [root@thermalite ~]# systemctl restart fetchmail |
# 5. check status of fetchmail service
1 2 3 4 5 6 7 8 9 10 11 12 | [root@thermalite ~]# systemctl status fetchmail ● fetchmail.service - A remote-mail retrieval utility Loaded: loaded (/usr/lib/systemd/system/fetchmail.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2020-08-10 14:12:03 EDT; 25min ago Main PID: 326506 (fetchmail) Tasks: 1 (limit: 48942) Memory: 2.7M CGroup: /system.slice/fetchmail.service └─326506 /usr/bin/fetchmail -d 300 --fetchmailrc /etc/fetchmailrc.example Aug 10 14:12:03 thermalite.localdomain systemd[1]: Started A remote-mail retrieval utility. [root@thermalite ~]# |
# 6. location of mail for mailex
1 2 3 | [root@thermalite ~]# ls -l /var/mail/malex -rw-rw----. 1 malex mail 281355833 Aug 10 14:34 /var/mail/malex [root@thermalite ~]# |
# 7. view mails using mailx
1 2 3 4 5 6 7 8 9 10 | [malex@thermalite ~]$ mail Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/malex": 4764 messages 2 new 4755 unread U4741 eBay Mon Aug 10 14:26 1696/120756 "Save big at The Brand Outlet 👟🎧️" U4745 Macy's Mon Aug 10 14:26 1182/67493 "Wknd fun: 40-60% off Deals of the Day!" U4748 JCPenney Mon Aug 10 14:26 1423/71443 "This EXTRA 30% OFF is yours, just in time for back to school!" U4758 Kohl’s Mon Aug 10 14:31 774/72915 "Save $10 + shop gotta-have gifts for every budget 🎁🎁🎁" U4759 Walgreens Photo Mon Aug 10 14:31 889/40013 "40% off Everything Photo! Create and pick up gifts all in the same day!" >N4760 Walgreens Photo Mon Aug 10 14:31 852/38092 "Get up to 50% off gifts + create & pick up SAME DAY = last-minute gifts that don’t fee" & |
No comments:
Post a Comment