Showing posts with label E-Mail. Show all posts
Showing posts with label E-Mail. Show all posts

Wednesday, December 4, 2013

Smarthost With SMTP Authentication For Sendmail

First we have to create the authentication information
cd /etc/mail
mkdir auth
chmod 700 auth
cd auth
vi client-info
Enter the following, substituting the desired mail server, username and password
AuthInfo:mail.server.com "U:username" "P:password"
Now we create the hash
makemap hash client-info < client-info
chmod 600 client-info*
cd /etc/mail
vi sendmail.mc
Now we tell sendmail to smarthost and use our authentication hash, substituting the desired mail server
define(`SMART_HOST',`mail.server.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
Find the existing line for smarthost and replace it with those three lines.

Lastly, rebuild the config and restart sendmail
m4 sendmail.mc > sendmail.cf
service sendmail restart

Thursday, April 11, 2013

DKIM Key 1024 2048 Bits Causes BIND NAMED Error

By default BIND can only handle 255 characters per line for record length, however it can handle values up to 65,536 characters.

The trick to getting a DKIM key (or any zone record for that matter) to wrap within this limit you do the following:
_domainKey.domain.com. IN  TXT ( "p=part of your key"
                                  "another part of your key"
                                  "last part of your key" )
By wrapping the entire value in brackets we keep it tied to one record and by quoting each line individually it allows us to surpass the line limit.

Common errors with this:
dns_rdata_fromtext: near eol: unbalanced quotes
dns_master_load: label too long
dns_master_load: syntax error
zone: loading master file: ran out of space

Thursday, January 31, 2013

Find All Catch-All Emails On DirectAdmin

find /etc/virtual -name "aliases" -exec grep -H "*: " {} \; | grep -v "fail" | grep -v "blackhole"

Wednesday, January 16, 2013

Monday, January 14, 2013

Block Outbound Port 25 SMTP For Untrusted Users With IPtables

This will only allow port 25 access to users: mail, mailman and root
iptables -A OUTPUT -d 127.0.0.1 -p tcp -m tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 25 -m owner --gid-owner mail -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 25 -m owner --gid-owner mailman -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 25 -m owner --uid-owner root -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 25 -j REJECT --reject-with icmp-port-unreachable

Tuesday, October 2, 2012

Enable SPF On All cPanel Accounts

for i in `ls /var/cpanel/users/`;do /usr/local/cpanel/bin/spf_installer $i ;done

Enable DKIM On All cPanel Accounts

for i in `ls /var/cpanel/users` ;do /usr/local/cpanel/bin/dkim_keys_install $i ;done

Friday, September 28, 2012

Delete All Messages In Qmail Spool With Plesk

/usr/local/psa/admin/bin/mailqueuemng -D
This works (at the very least) on Plesk 9.5.x

Wednesday, September 26, 2012

Sending Email From A Bash Script

#!/bin/bash
CONTENT="This is the content"
SUBJECT="This is the subject"
TO_ADDRESS=destination_email_address_here
FROM_ADDRESS=source_email_address_here

echo $CONTENT | mail -s $SUBJECT $TO_ADDRESS -- -r $FROM_ADDRESS
Note:
The -- delimits that the options following it are piped to sendmail

Thursday, July 12, 2012

Enable All Services For A Domain Using Vpopmail

domain=$1
vpmdir=/home/vpopmail
acctlist=$(find $vpmdir/domains/$domain -mindepth 1 -maxdepth 1 -type d) for acctpath in $acctlist; 
do
     account=${acctpath##*/}
     address=$account@$domain
     echo "changing $address"
     $vpmdir/bin/vmoduser -x $address
done 
Usage ./[the_above_script]/[domain]

Disable All Services For A Domain Using Vpopmail

domain=$1
vpmdir=/home/vpopmail
acctlist=$(find $vpmdir/domains/$domain -mindepth 1 -maxdepth 1 -type d) for acctpath in $acctlist; 
do     
     account=${acctpath##*/}
     address=$account@$domain
     echo "changing $address"
     $vpmdir/bin/vmoduser -p -s -w -i -r $address
done 
Usage ./[the_above_script]/[domain]

Monday, May 21, 2012

Sending E-Mail As An Authenticated User Using Telnet

The first thing you have to do is generate your AUTH PLAIN token from the command line (assuming Linux):
perl -MMIME::Base64 -e 'print encode_base64("\000your-user\@your-domain.com\000your-password");' 
Now telnet to your mail server:
telnet mail.your-domain.com
Trying 1.2.3.4...
Connected to mail.your-domain.com.
Escape character is '^]'.
220 mail.your-domain.com ESMTP
Now we need to say Hi:
ehlo my-current-hostname.com
And we'll receive the list of supported commands:
220 mail.your-domain.com ESMTP
250-mail.your-domain.com
250-STARTTLS
250-PIPELINING
250-8BITMIME
250-SIZE 0
250 AUTH LOGIN PLAIN CRAM-MD5
We want to AUTH PLAIN using the token we created:
AUTH PLAIN [token here]
If your login credentials are accepted you'll receive:
235 ok, go ahead (#2.0.0)
Now you can send a message (I've included the numeric response codes below each command, you wouldn't enter those):
MAIL FROM: your-user@your-domain.com
250 ok
RCPT TO: another-user@another-domain.com
250 ok
DATA
354 go ahead
To: another-user@another-domain.com
From: your-user@your-domain.com
Subject: This Is How To Send An Authenticated Email Via Telnet 
Date: Mon, 21 May 2012 12:00:00 -0500
Testing auth plain via telnet.
To end the message well place a period on it's own line and then hit enter.
.
250 ok
QUIT
And there you have it!

Wednesday, December 14, 2011

Track And Log Formmail SPAM In cPanel

First step is to move the sendmail binary
mv /usr/sbin/sendmail /usr/sbin/sendmail.act

Create a "new" sendmail binary
vi /usr/sbin/sendmail

...and add:
#!/usr/bin/perl

# use strict;
use Env;
my $date = `date`;
chomp $date;
open (INFO, ">>/var/log/formmail.log") || die "Failed to open file ::$!";
my $uid = $>;
my @info = getpwuid($uid);
if($REMOTE_ADDR) {
print INFO "$date - $REMOTE_ADDR ran $SCRIPT_NAME at $SERVER_NAME \n";
}
else {

print INFO "$date - $PWD - @info\n";

}
my $mailprog = '/usr/sbin/sendmail.act';
foreach (@ARGV) {
$arg="$arg" . " $_";
}

open (MAIL,"|$mailprog $arg") || die "cannot open $mailprog: $!\n";
while (<stdin> ) {
print MAIL;
}
close (INFO);
close (MAIL);

Lastly:
chmod +x /usr/sbin/sendmail
echo > /var/log/formmail.log
chmod 777 /var/log/formmail.log