Archive for February, 2010

How to send mail in command line interface

.
Hi again.
In the linux CLI you can easily send mail your files or texts you want. just you can use the nail command.

nail -r “myaddress@something.com” -s “Some subject” -S smtp=some.smtp.server info@company.com < msg.txt

also you can permanently set the SMTP server in your ~/.mailrc file (or /etc/nail.rc if you want to set it system-wide), which removes the need for using the “-S smtp=…” option on the command-line:

set smtp=some.smtp.server

the second way you can use the following script i download from internet :

#!/usr/bin/env python

# Usage: ./mail.py

import sys
import smtplib

def prompt(prompt):
return raw_input(prompt).strip()

def create_message():
fromaddr = prompt(‘From: ‘)
toaddrs = prompt(‘To: ‘).split()
subject = prompt(‘Subject: ‘)
print ‘Enter message, end with ^D (Unix) or ^Z (Windows): ‘
msg = (‘From: %s\r\nTo: %s\r\nSubject: %s\r\n\n’ \
% (fromaddr, ‘, ‘.join(toaddrs), subject))
while 1:
try:
line = sys.stdin.readline()
except EOFError:
break
if not line:
break
msg = msg + line
return fromaddr, toaddrs, msg

def send_mail(fromaddr, toaddrs, msg):
server = smtplib.SMTP(‘localhost’)
server.sendmail(fromaddr, toaddrs, msg)
server.quit()

def main():
[fromaddr, toaddrs, msg] = create_message()
send_mail(fromaddr, toaddrs, msg)

if __name__ == ‘__main__’:
main()

regards

Postfix Virtual Domain Hosting Howto

.

Hi again

regarding one of my previous post which was about installing the postfix with spam filtering, i decided to write about the another capability of the postfix. the ability of serving to multiple domain. it could be configured with my_destination option but i highly recommended you to  enable it as virtual domain hosting.

the option you should add to your main.cf file (main configuration file of postfix commonly placed in /etc/postfix) are :

virtual_alias_domains = mehdibehamin.com , mehdibehamin2.com, mehdibehamin3.com
virtual_alias_maps = hash:/etc/postfix/virtual

after all you should create a new file which name /etc/postfix/virtual and add the the following option in it.

$yourdomainname       virtual

postmaster@$yourdomainname  user1

info@$yourdomainname  user2

@$yourdomainname user1

the second line indicates that the the mail postmaster@$yourdomainname should be forwarded to user1 of your linux system.

and the last says all the other email address with your domain suffix will be forwarded to user1.

then you should create the db file for your virtual file.

postmap /etc/postfix/virtual

then you should link it to your postfile chroot address.

ln -s /etc/postfix/virtual.db /var/spool/postfix/etc/

then reload your postfix service :)

reference : http://www.afp548.com/articles/Panther/postfixvirtual.html

thats it.

regards

fatal: open database /etc/postfix/virtual.db: No such file or directory

.

Hi again

in order to cover this error you should first create your virtual.db file, by typing the following command.

postmap /etc/postfix/virtual

but perhaps this problem still exists. as i wrote in my previous posts the postfix uses chroot by default. therefore you need to link the virtual.db file into the postfix root directory.

ln -s /etc/postfix/virtual.db /var/spool/postfix/etc/

after that the error should be eliminated from your mail log files.

regards

ln -s /etc/postfix/virtual.db /var/spool/postfix/etc/

How to configure DNS Server for Mail Server on Linux

.

Hi again

First you should install the BIND DNS package in your linux server. you can simply install either with aptitude and yum installer or compile it  in your linux. (if you decided to compile approach just wait , i will explain you in my few next posts.)

so you should type:

aptitude install bind9

or

yum install bind.i386

(if you don’t know what exactly the name of package is, you can simply search your package name via the installer. for instance aptitude search bind)

then you should configure your mail server.

the main configuration file of the BIND by default is in the /etc/bind/ directory. therefore you start edit your named configuration files.

vim /etc/bind/named.conf

add the blow configuration before the last  }; in the file.

zone “mehdibehamin.com” {
type master;
file “/etc/bind/mehdibehamin.local”;
};

as you sea you should create the zone configuration file. for instance in the above configuration i set it as mehdibehamin.local.

therefore save the named.conf and in the /etc/bind/ create the new file with the mentioned name.and insert these configuration in it.

$TTL    86400
@               IN              SOA              mehdibehamin.com. root.mehdibehamin.com. (
1                                                                                                                                                                    ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
86400 )       ; Negative Cache TTL
;
@                         IN                NS              mehdibehamin.com.
www                 IN                 A                 1.2.3.4
mx                     IN                 A       192.168.0.1
mehdibehamin.com      IN      MX      10      mx.mehdibehamin.com.

note: you can copy the template of the configuration file from /etc/bind/db.local and then edit it :)

with the last configuration line all the packet which mail server sent to whatever@mehdibehamin.com transmited into 192.168.0.1 ip address. (which is the smpt or mail server IP address).

thats it.

regards

How to Enable or Disable Simple File Sharing in Windows XP

.

Hi again

to Enable or Disable Simple File Sharing in Windows XP , you should follow this instruction.

1. Click Start, and then click My Computer.

2. On the Tools menu, click Folder Options.

3. Click the View tab.

4. In the Advanced Settings section, click to clear the Use simple file sharing (Recommended) check box.

5. Click OK.

Reference : http://support.microsoft.com/kb/307874

regards

warning: SASL authentication problem: unable to open Berkeley db /etc/sasldb2: No such file or directory

.

Hi again

if you face with this error you should just copy the /etc/sasldb2 file into the postfix root (mostly /var/spool/postfix/etc)

then restart your postfix :)

regards

How to setup Linux Mail Server (Postfix + Dovecot + SASL + Spam Filtering)

.

Hi again.

Firstly i thank ray ban store , Robert Shumake and Mohsen Amiri for their reading and commenting my posts.

when i searching the internet i found that there is no complete reference for installing the mail server in linux. therefore i decided to add the blog entry to define the complete process of  installing the mail server with spam filtering.

note that all the actions i will talk are in Debian Linux Environment which is my favorite Linux distribution however all these action can be run in other distribution with a little changes. if you have problem with other distribution just let me know.

ok lets do it.

At first you should download the necessary packages:

now start installing MTA (Mail Transferring Agent)

aptitude install postfix postfix-tls libsasl2 sasl2-bin libsasl2-modules popa3d

after installing you should start configuring your postfix service therefore

vim /etc/postfix/main.cf

then add the following code to your configuration file.

myhostname = MailServer.mehdibehamin.com
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname  ## check that the name is correct
mydestination = mehdibehamin.com ## in order to receive username@mehdibehamin.com mails
relayhost =
mynetworks = 10.10.0.0/24 10.10.10.0/24 127.0.0.1/32 ## Note that you should insert the 127.0.0.1

#due to connection to clamav in future

mailbox_command = procmail -a “$EXTENSION”
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

and the start to configuring the other option may you need to set in your postfix service. (please override the above configuration if any exist in your file).  honestly we should check our postfix config file again in few next steps.

ok, after installing the postfix, you should install the IMAP/POP3 servers. its so easier than the postfix :) just run the following commands.

aptitude install dovecot-imapd dovecot-pop3d dovecot-common

after installing process would be finished. open the configuration file and start to uncomment some configuration option of the dovecote

vim /etc/dovecot/dovecot.conf

and uncomment the following option :

protocols = pop3 imap

disable_plaintext_auth = no
pop3_uidl_format = %08Xu%08Xv

(Hummm, you can find these option in vim environment by type “/$your search Criteria ‘ )

now you can start to add users. simply add user with command adduser $yourNewUser

then restart your postfix and dovecote services.

now its the turn of SASL. but let me to explain something. for the security reason the postfix use the chroot directory and if you want to address some files to the postfix (eg some other extra files), you should copy or link them to the root directory of the postfix. (mostly /var/spool/postfix).

ok back to our mail server isntalatin.

again you should edit the postfix main configuration file.

vim /etc/postfix/main.cf

and add the following options

smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = yourdomain.com
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination ##
Note that this option should be optimized for spam filtering :)
smtpd_sasl_security_options = noanonymous

but for start using of the sasl ,still there is somthing to do.

you should remove the current sasl directory and link it to the postfix root folder.

rm -r /var/run/saslauthd/

mkdir -p /var/spool/postfix/var/run/saslauthd

ln -s /var/spool/postfix/var/run/saslauthd /var/run

chgrp sasl /var/spool/postfix/var/run/saslauthd

adduser postfix sasl

and then you should edit your dovecote configuration file again:( therefore again

vim /etc/dovecot/dovecot.conf

auth default {
mechanisms = plain login
passdb pam {
}
userdb passwd {
}
socket listen {
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}

}

}

ok almost done. now you have a mail server working on linux but there is very important **point.**

mail server works based on the MX (Mail Exchange) DNS records. so if you want to test you mail server, you should configure your DNS server. (i will let you know how to configure your dns in my next post)

OK, but there is something left. till now we install the mail server which is perfect for  clients. but if we want to connect your mail server to the internet there are many unauthorized users who use your mail server to send their spam or mails which cause many mail servers in internet block your mail server IP address. therefor we should configure mail server so that misuse are minimized.

in the postfix there are few configuration option which helps us to reduce the misusing of the unknown clients. there are some rules that the server should obey. for instance reject the unregistered IP address (mostly they are dynamic IPs which ISP leased to their clients eg).

iv made some configuration which you can add to your postfix configuration file.



default_destination_rate_delay = 10

default_destination_recipient_limit = 5

default_extra_recipient_limit = 50

smtpd_recipient_limit = 50

smtpd_helo_required = yes

disable_vrfy_command = yes

strict_rfc821_envelopes = yes

invalid_hostname_reject_code = 554

multi_recipient_bounce_reject_code = 554

non_fqdn_reject_code = 554

relay_domains_reject_code = 554

unknown_address_reject_code = 554

unknown_client_reject_code = 554

unknown_hostname_reject_code = 554

unknown_local_recipient_reject_code = 554

unknown_relay_recipient_reject_code = 554

unknown_sender_reject_code = 554

unknown_virtual_alias_reject_code = 554

unknown_virtual_mailbox_reject_code = 554

unverified_recipient_reject_code = 554

unverified_sender_reject_code = 554

disable_vrfy_command = yes

smtpd_delay_reject = yes

smtpd_helo_required = yes

smtpd_helo_restrictions = permit_mynetworks, reject_non_fqdn_hostname, reject_invalid_hostname, permit

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_invalid_hostname, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_rbl_client list.dsbl.org, reject_rbl_client sbl.spamhaus.org, reject_rbl_client cbl.abuseat.org ,  reject_rbl_client dul.dnsbl.sorbs.net,  reject_rbl_client multi.uribl.com,  reject_rbl_client dsn.rfc-ignorant.org,  reject_rbl_client dul.dnsbl.sorbs.net,  reject_rbl_client sbl-xbl.spamhaus.org, reject_rbl_client bl.spamcop.net,  reject_rbl_client ix.dnsbl.manitu.net,  reject_rbl_client combined.rbl.msrbl.net,  reject_rbl_client rabl.nuclearelephant.com,  permit,  reject

### i changed the default values to my optimum way based on my network. you should do the same

smtpd_error_sleep_time = 1s

smtpd_soft_error_limit = 10

smtpd_hard_error_limit = 20

smtp_client_restrictions = permit_mynetworks,  permit_sasl_authenticated,  reject_maps_rbl, reject_unknown_client

(references :  http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu-9.10-p3

http://www.cs.uu.nl/technical/services/email/spam-policy.html

http://www.ax11.de/howtos/postfix-antispam-howto.html#files

http://www.debianadmin.com/debian-mail-server-setup-with-postfix-dovecot-sasl-squirrel-mail.html )

thats it.  the above configuration will prevent many spams. but i recommend you to add an anti virus to your mail server.

Be patient, there is one step left and that is installing the anti spam .

apt-get install clamsmtp clamav-freshclam

Edit the  /etc/clamsmtpd.conf  file and change  
OutAddress: 10025 to OutAddress: 10026.
also change
Listen: 127.0.0.1:10026 to Listen: 127.0.0.1:10025

then edit the postfix main configuration file again
and add the following options :)  

vim  /etc/postfix/main.cf
content_filter = scan:127.0.0.1:10025
receive_override_options = no_address_mappings

also 

vim etc/postfix/master.cf
# AV scan filter (used by content_filter)
scan      unix  -       -       n       -       16      smtp

        -o smtp_send_xforward_command=yes

# For injecting mail back into postfix from the filter

127.0.0.1:10026 inet  n -       n       -       16      smtpd

        -o content_filter=

        -o receive_override_options= no_unknown_recipient_checks,
no_header_body_checks

        -o smtpd_helo_restrictions=

        -o smtpd_client_restrictions=

        -o smtpd_sender_restrictions=

        -o smtpd_recipient_restrictions=permit_mynetworks,reject

        -o mynetworks_style=host

        -o smtpd_authorized_xforward_hosts=127.0.0.0/8

(reference : http://www.debian-administration.org/articles/259 )

now restart your server and check for the errors and logs on
/var/log/mail.log or /vae/log/mail.err

now you can test your anti-virus by sending the mail with the
following content 

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

 :)  thats it.
it should be recognize the following command as virus.
it is not a real virus but a test string called the Eicar.

and finally you can update your antivirus engine manually by
entering freshclam command.
yeah thats it!!! you configure your mail server with spam filtering. 

Note: by the way dont forget to configure your sasld to start.
 vim /etc/default/saslauthd
and change START=no to START=yes.

there are many other option available but they are really should
be set based on your network conditioned.
therefore if you have any question dont hesitate to ask me later.

regards
aptitude install dovecot-imapd dovecot-pop3d dovecot-common

     Copyrighted Mehdi Behamin , All Rights Reserved
    
Blog has been visited 186959 times