After doing en extensive research on the net for a similar setup (without finding anything) and spending a full weekend trying to get this working, I've decided to create a tutorial that will provide a base to users that don't have a lot of mail server experience and the same setup.
I'm an email guy so I'm not sure if I'll be able to support in case you run into problems, but I'll try if I can. Also let me know if you think there's some wrong with the tutorial or anything that can be improved and I'll be happy to change.
Here's what I have at home:
- Ubuntu Server 8.10 32-bit (LAMP)
- dyndns
- Yahoo mail (not plus)
1- Getting your emails delivered to your account
1.a - Install fetchmail$ sudo aptitude install fetchmail
1.b - Create a .fetchmailrc in your home directory with the following info:$ cd $HOME
$ vim .fetchmailrc
set syslog;
set daemon 90;
set postmaster "[user]@yahoo.ca";
poll "pop.mail.yahoo.ca" port 995 with protocol POP3 user "user@yahoo.ca" password "[yahoo_password]" is "[loginname_to_the_server]" here keep ssl
smtphost "localhost" smtpname "[loginname_to_the_server]@localhost"
Note: Do no use the square brackets. They are there only to indicate that you need to enter something.
- The above file will download only new emails and keep a copy on the server
1.c - Change permission of the file$ chmod 600 .fetchmailrc
1.d - Run fetchmail and check if new mail has arrived (make sure that there's one unread email on your yahoo account)$ fetchmail
$ mail
- Press “q” to leave the mail reader
2- Setup postfix to delivery the messages for you
By default postfix should already be installed on your machine. But you still need to configure it do delivery your local emails to your local or Internet accounts.
2.a - Initial postfix configuration$ sudo dpkg-reconfigure postfix
Answer the questions at the prompt:
General type of mail configuration: Internet Site
NONE doesn't appear to be requested in current config
System mail name: server1.example.com
Root and postmaster mail recipient:
Other destinations for mail: server1.example.com, example.com, localhost.example.com, localhost
Force synchronous updates on mail queue?: No
Local networks: 127.0.0.0/8
Yes doesn't appear to be requested in current config
Mialbox size limit (bytes): 0
Local address extension character: +
Internet protocols to use: all
Once this is set you should be able to send emails locally. Restart postfix and try sending an email to yourself with the following command:$ sudo /etc/init.d/postfix restart
$ mail [your_user_name]@localhost
Subject: Testing
This is a test # press Ctrl+d to end the message body
Cc: # press enter
$ mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/user": 1 messages 1 new
> N 1 user@hostname Sun Jun 7 20:08 14/464 Testing
2.b - Fine tunning postfix
Check the following file and make sure that it has you server's FQDN$ cat /etc/mailname
myserver.dyndns.org
Now we need to create an authorization file that will be used for your login and them run postmap on it to create a db file. The file should look like this:$ sudo cat /etc/poistfix/sasl/smtp_auth
127.0.0.1 [username]@yahoo.ca:[password ]
$ sudo postmap /etc/poistfix/sasl/smtp_auth
Let's edit your postfix mail file to look similar to this:$ grep -v '#' /etc/postfix/main.cf
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = yes
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=no
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = [fqdn], [hostname].[domain_name,] localhost.[domain_name], localhost
relayhost = 127.0.0.1:11125 # this will be used with stunnel
mailbox_command = procmail -a "$EXTENSION" DEFAULT=$HOME/Maildir/
MAILDIR=$HOME/Maildir
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl/smtp_auth
If everything went ok we can go to next step and install stunnel and configure for sending the email via port 465 (which is no longer supported by postfix).
3 - Stunnel
3.a - Installing and configuring stunnel$ sudo aptitude install stunnel
And configure you stunnel.conf to look like this:$ grep -v ';' /etc/stunnel/stunnel.conf
sslVersion = SSLv3
chroot = /var/lib/stunnel4/
setuid = stunnel4
setgid = stunnel4
pid = /stunnel4.pid
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
client = yes
[smtps]
accept = 11125
client = yes
connect = smtp.mail.yahoo.ca:465
# Make sure that the following lines are commented out:
;cert = /etc/stunnel/mail.pem
;cert = /etc/stunnel/stunnel.pem
;key = /etc/stunnel/mail.pem
3.b - Starting and testing stunnel$ sudo /etc/init.d/stunnel4 start
$ telnet 127.0.0.1 11125
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 smtp107.mail.mud.yahoo.com ESMTP
>ehlo
250-smtp107.mail.mud.yahoo.com
250-AUTH LOGIN PLAIN XYMCOOKIE
250-PIPELINING
250 8BITMIME
>quit
221 smtp107.mail.mud.yahoo.com
Connection closed by foreign host.
At this point you should be able to send and receive email from your yahoo account using the mail command. If for some reason you are having problems, check the troubleshooting section at the end of the tutorial for more help and links.
4 - Dovecot
4.a - Installing dovecot$ sudo aptitude install dovecot-common dovecot-imapd dovecot-pop3d
4.b - Configuring and testing dovecot
Dovecot is very straight forward for configuring. Check that /etc/dovecot/dovecot.conf has the following lines:protocols = imap imaps pop3 pop3s
protocols = imap imaps pop3 pop3s
mail_privileged_group = mail
Restart it and then we can test it with mutt:$ sudo /etc/init.d/dovecot restart
$ mutt -f imap://user@127.0.0.1/
5 - Configuring an email client
Most email clients are the same. I'll include here the basic settings that you will need to connect using the settings we have just created
=> Receiving email
Server: FQDN
Username: local username for the server
Security: TLS
=> Sending email
Server: FQDN
Security: No encryption
6 - Troubleshooting
6.a Useful commands
Commands to display and purge emails on the server:# prints messages in queue
$ postqueue -p
# attempts to send messages - flush
$ postqueue -f
Check your logs for important messages as you attempt to send emails and start services$ sudo tail -f /var/log/mail.log
6.b - Useful links
- Ubuntu Documentation for postfix
https://help.ubuntu.com/community/Postfix
- Postfix as client only (what we used here)
http://www.postfix.org/SASL_README.html#client_sasl
- Postfix port 465
http://www.postfix.org/TLS_README.html
- Postifx authentication file
http://www.postfix.org/postconf.5.html#smtp_sasl_password_maps
- Relaying to an smtps host with postfix and stunnel
http://www.eglug.org/book/export/html/1923
- Generates pem key for stunnel (we are not using it here)
http://www.stunnel.org/pem/
- Troubleshooting stunnel
http://ubuntuforums.org/showthread.php?t=983926
- Postfix and Dovecot on Ubuntu Dapper Drake
http://adomas.org/2006/08/postfix-dovecot/
Sunday, June 7, 2009
How to Yahoo IMAP with postfix, fetchmail and dovecot
Posted by Victor at 6:15 PM 3 comments
Labels: Server
Monday, May 18, 2009
How to move pictures by resolution
This post will help you organize your pictures by resolution into subfolders, making it easier to use with machines that have different monitor size.
I myself like to have my files very organized, and one of the problems I have once in a while is that at home my laptop is always plugged into my widesreen monitor, however when I'm on the road my laptop only supports 1024x800 resolutions. This results in having some of the wallpapers not look good when moving from home setup to road, and vice versa.
So I came up with a simple line of codes using the package “imagemagick”.
1- Make sure that the images have no space in their names. One way of solving this for bulk files is by using 'convert', which also comes with imagemagick:convert 's/ //g' *
2- Sort items by resolution# folder with images only
identify * | awk '{ print $3 }' | sort -n
# folder with files and images
for i in $(ls *jpg *png *gif *JPG *JPEG 2> /dev/null) ; do identify "$i" | awk '{ print $3 }' | sort -n ; done
3- You should now get a list of the different resolutions for the pictures in the folder, similar to the one below:$ identify * | awk '{ print $3 }' | sort -n
1024x768
1024x768
1024x768
1024x768
1024x768
1280x1024
1280x1024
1280x1024
1280x1024
1400x1050
1600x1000
1600x1129
4- Create a folder for each of the resolutions and then set the local variable “_res” with the resolutions of the “turn”:_res="1024x768"
5- Run the code that will organize the pictures into folders:for i in "$(identify *jpg *png *gif 2> /dev/null | grep "$_res")" ; do mv $(echo "$i" | awk '{ print $1 }' | sed 's/\[.*\]//g') $_res/ ; done
6- Repeat steps 4 and 5 for the remaining files
Posted by Victor at 6:31 PM 0 comments
Labels: Shell Tips
Saturday, April 4, 2009
How to use script highlight on 'less' (vim)
The title might be a bit misleading. As far as I know 'less' does not support script highlight (please correct me if I'm wrong). However I did find out that vim has a built-in script that allows you to use it as less.
So here's a very simple solution, add an alias to your ~/.bashrc pointing the vim script:alias lessv='/usr/share/vim/vim71/macros/less.sh'
You can see from the screenshot bellow that the file is open as read-only and not modifications are allowed. Some of 'less' commands (like “q” to quit) are also replicated.
Posted by Victor at 8:03 PM 0 comments
Friday, April 3, 2009
How to display variables without case sensitivity
This is the second of many shell (bash) tips that I'll be posting here. This little script will allow you to display the value of variables without having case sensitiveness or having to enter the “$” before the variable name.
Here's what displaying a variable without the script looks like:$ echo $PATH
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
And here after the script:$ var path
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
$ var PATH
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
You can see that both ways will work (as long as the variable does not have the same name in lower and capital case).
And here's the script, which can also be added to ~/.bashrcvar ()
{
_var="$1";
if [ -n "${!_var}" ]; then
echo ${!_var};
else
_var=$(echo "$_var" | tr 'a-z' 'A-Z');
echo ${!_var};
fi
}
Posted by Victor at 8:43 PM 0 comments
Sunday, March 29, 2009
Getting daily tips for bash
I still consider my self a new Linux user and a noobie. One of the things that I strive to learn is scripting in bash, but I do have difficulties as I have no programing background, so I try to read and get as much help as I can.
During my searches on the web I found a very interesting twitter profile for the author of “O'Reilly's Bash Cookbook”. He has daily updates with interesting bash tips, which I have found very useful.
So today I'll be providing a function script that can be added to your ~/.bashrc and used as either a command or a welcome message for you terminal emulator. This script will go to the twitter profile of “Bash cookbook” and download their daily content.
The script is compatible with links and elinks (Red Hat) for downloading the content. It creates 3 environment variables on your system to hold links version, last update and downloaded content.
Open you ~./bashrc with your favourite text editor and paste the lines bellow:bash_tips ()
{
# checks for version of links
if [ -z "$LINKS_VERSION" ] ; then
export LINKS_VERSION=$(links -version | grep Links | cut -f1 -d" ")
fi
# checks variable that holds last update time
if [ "$BASH_TIPS_DATE" != $(date "+%d") ] ; then
export BASH_TIPS_DATE=$(date "+%d")
if [ "$LINKS_VERSION" = "ELinks" ] ; then
# script for ELinks
export BASH_TIPS=$(links -dump -dump-width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
else # script for Links
export BASH_TIPS=$(links -dump -width 300 http://twitter.com/bashcookbook | egrep '^ *1\. [^http]' | sed 's/^ *//g')
fi
fi
echo -e "\n## Today's bash tips ##\n$BASH_TIPS"
}
If you want to have the daily tips displayed when you open a terminal emulator, just add “bash_tips” to your ~/.bashrc.
This is what they will look like:victux ~ $ bash_tips
## Today's bash tips ##
1. Using += on an array assignment adds new elements to the array. If RA has element 0-6 then RA+=(new elems) creates RA[7] and RA[8].10:24 PM Mar 27th from Identica
Book:
http://oreilly.com/catalog/9780596526788/
Twitter site:
http://twitter.com/bashcookbook
Official site:
http://www.bashcookbook.com/
Posted by Victor at 8:19 PM 0 comments
Thursday, March 26, 2009
How to highlight pdf files on Linux and Windows machines
Two annoyances that I have always had with ebooks and pdf material is that when I'm reading I like to highlight important info for future reference. Most readers (like Adobe) only allows you to highlight files that you have document rights to it, which I don't think makes any sense.
The other problem is that I read the same book between multiple computers and multiple platforms. I always have to write down the page I read last, and this is a bit annoying.
After doing a lot of searches I was finally able to find a pdf reader (PDF-XChange Viewer) that allows me to highlight text and save that information. Even better, they have a portable version so you can have the book, program and saved data (highlight and page) on a USB device and access it between machines.
For my utmost surprise the program works under wine and also reads the saved data.
Hot to get it working
1- Download the portable version of the program and unzip it to your flash device (either on Linux or Windows)
http://www.docu-track.com/download/PDFX_Vwr_Port.zip
2- Install wine on your Linux machine if you have not already done so# Ubuntu (8.10)
$ sudo aptitude install wine
$ winecfg
3- Create a script in the flash drive within the program folder to open the program on Linux $ echo -e '#!/bin/bash\n\nwine PDXCview.exe &' > PDFXCview_for_Linux
You should now be able to open the program on either Windows or Linux and see your highlighted text.
Posted by Victor at 9:10 AM 3 comments
Labels: Hacking
Friday, February 27, 2009
Giving Life to Old Computer Hardware
The other day I was trying to come up with ideas on how to use some of the old computer hardware I have laying around at home. I searched the web over and over for computer hardware decor and similar keywords, and finally after a lot of searching I started to find some cool ideas (which I'll be showing here).
1- Floppy notes
This is actually pretty cool. Some companies actually sell this (between 2-10 US) on the net. But I think everyone has a few old floppies at home that have no use.
2- Floppy pencil holder
Another good idea for floppies. This is also being sold on the net (or you can easily make your own).
3- Hard Drive clock
No need to say much. This is a fully functional clock installed on an old HD. You can get instructions from here: http://www.instructables.com/id/Hard-drive-platter-clock./
There are many more ideas that I have not had a chance of trying, but I'm including a link with all my findings here if you want to dig a bit further.
http://delicious.com/victorbrca/Computer%2FHardware%2FDecor
And here are more links for my preferred ones:
- Really amazing LED clock
http://www.ian.org/HD-Clock/
- Bag made with floppy disks
http://www.instructables.com/id/Floppy-Disk-Bag/
Posted by Victor at 7:05 PM 1 comments