From Halfface
Jump to navigation Jump to search

resend mails in queue

sendmail -q -v

resend a mail in mbox format

cat /tmp/sendmail.txt | sendmail -i -t -v

delete mails from a recipiant

sendmail -qR -v

Who owns mails with problem

mailq | grep @ | grep -v ^k | cut -d \< -f 2 | cut -d @ -f2 | awk '{print $1}' | sort | uniq -c | sort -n | grep -v `hostname` | cut -d \> -f 1| tail

send mail with telnet

[user@host]# telnet 25
Connected to (
Escape character is '^]'.
250 sender <> ok
250 recipient <> ok
354 go ahead
From: [Alice Hacker] <>
To: [Bob Smith] <>
Date: Mon, 12 Apr 2010 14:21:26 -0400
Subject: Test Message

Hi there!
This is supposed to be a real email...

Have a good day!

250 ok:  Message 222220902 accepted
Connection closed by foreign host.

send mail via telnet and expect

set mailserver [lrange $argv 0 0]
set from [lrange $argv 1 1]
set to [lrange $argv 2 2]

spawn telnet $mailserver 25
expect "failed" {
                send_user "$mailserver: connect failed\n"
        } "2?? *" {
        } "4?? *"   {
        } "refused" {
                send_user "$mailserver: connect refused\n"
        } "closed" {
                send_user "$mailserver: connect closed\n"
        } timeout {
                send_user "$mailserver: connect to port 25 timeout\n"
send "HELO\r"
expect "2?? *" {
} "5?? *" {
} "4?? *" {
send "MAIL FROM: <$from>\r"
expect "2?? *"  {
} "5?? *" {
} "4?? *" {
send "RCPT TO: <$to>\r"
expect "2?? *" {
} "5?? *" {
} "4?? *" {
send "DATA\r"
expect "3?? *" {
} "5?? *" {
} "4?? *" {
send "From: $from\r"
send "To: $to\r"
send "Subject: test\r"
send "This is a test message\r"
send ".\r"
expect "2?? *" {
} "5?? *" {
} "4?? *" {
send "QUIT\r"

SMTP servers for internet providers 		smtp		smtp


set smarthost and domain. /etc/mail/ define(`SMART_HOST', `')


sendmail listen on all network interfaces

Enable smtp on all interfaces.

/etc/mail/ DAEMON_OPTIONS(`Port=smtp,Name=MTA')dnl


/etc/mail/virtusertable bjorklun bjorklun stannaks error:nouser 550 No such user here error:5.7.0:550 Address invalid bjorklun stannaks stannaks @mobbad. bjorklun bjorklun

aliases for your host

<verbatim> /etc/mail/local-host-names

Access rights. Who can send mail and username and password at smtp server.

<verbatim> /etc/mail/access

localhost.localdomain RELAY localhost RELAY RELAY RELAY RELAY "U:b586378" "I:b586378" "P:??????" "M:LOGIN PLAIN"

Forward a copy of email.



sending mail from command line

From: "From hoever" <>
To: "Andreas halfface Bjorklund" <>
Subject: Test Email
MIME-Version: 1.0
Content-Type: text/plain

Andreas Bjorklund doing test.

# cat /tmp/sendmail.txt | sendmail -i -t


   2.1.2. Header Field: From

       Mailbox of message author  
   Related information:
       Specifies the author(s) of the message; that is, the mailbox(es)
       of the person(s) or system(s) responsible for the writing of the
       message. Defined as standard by RFC 822.

   2.1.3. Header Field: Sender

       Mailbox of message sender  
   Related information:
       Specifies the mailbox of the agent responsible for the actual
       transmission of the message.  Defined as standard by RFC 822.

   2.1.22. Header Field: Return-Path

       Message return path
   Related information:
       Return path for message response diagnostics. See also RFC 2821
       [17]. Defined as standard by RFC 822.


What's the difference between the Envelope From and Sender and From in an email?

Basically Envelope From is used are part of the protocol and Send From is part of the data.

header fields

Accept-Language mail [RFC4021]
Alternate-Recipient mail [RFC4021]
Archived-At prov/archived-at mail standard [RFC5064]
Authentication-Results mail standard [RFC7601]
Auto-Submitted mail standard [RFC3834 section 5]
Autoforwarded mail [RFC4021]
Autosubmitted mail [RFC4021]
Bcc mail standard [RFC5322]
Cc mail standard [RFC5322]
Comments mail standard [RFC5322]
Content-Identifier mail [RFC4021]
Content-Return mail [RFC4021]
Conversion mail [RFC4021]
Conversion-With-Loss mail [RFC4021]
DL-Expansion-History mail [RFC4021]
Date mail standard [RFC5322]
Deferred-Delivery mail [RFC4021]
Delivery-Date mail [RFC4021]
Discarded-X400-IPMS-Extensions mail [RFC4021]
Discarded-X400-MTS-Extensions mail [RFC4021]
Disclose-Recipients mail [RFC4021] 
Disposition-Notification-Options mail [RFC4021]
Disposition-Notification-To mail [RFC4021]
DKIM-Signature mail standard [RFC6376]
Downgraded-Bcc mail obsoleted [RFC5504][RFC6857]
Downgraded-Cc mail obsoleted [RFC5504][RFC6857]
Downgraded-Disposition-Notification-To mail obsoleted [RFC5504][RFC6857]
Downgraded-Final-Recipient mail standard [RFC6857 Section 3.1.10]
Downgraded-From mail obsoleted [RFC5504][RFC6857 Section 3.1.10]
Downgraded-In-Reply-To mail standard [RFC6857 Section 3.1.10]
Downgraded-Mail-From mail obsoleted [RFC5504][RFC6857 Section 3.1.10]
Downgraded-Message-Id mail standard [RFC6857 Section 3.1.10]
Downgraded-Original-Recipient mail standard [RFC6857 Section 3.1.10]
Downgraded-Rcpt-To mail obsoleted [RFC5504][RFC6857]
Downgraded-References mail standard [RFC6857 Section 3.1.10]
Downgraded-Reply-To mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-Bcc mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-Cc mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-From mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-Reply-To mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-Sender mail obsoleted [RFC5504][RFC6857]
Downgraded-Resent-To mail obsoleted [RFC5504][RFC6857] 
Downgraded-Return-Path mail obsoleted [RFC5504][RFC6857]
Downgraded-Sender mail obsoleted [RFC5504][RFC6857]
Downgraded-To mail obsoleted [RFC5504][RFC6857]
Encoding mail [RFC4021]
Encrypted mail [RFC4021]
Expires mail [RFC4021]
Expiry-Date mail [RFC4021]
From mail standard [RFC5322][RFC6854]
Generate-Delivery-Report mail [RFC4021]
Importance mail [RFC4021]
In-Reply-To mail standard [RFC5322]
Incomplete-Copy mail [RFC4021]
Keywords mail standard [RFC5322]
Language mail [RFC4021]
Latest-Delivery-Time mail [RFC4021]
List-Archive mail [RFC4021]
List-Help mail [RFC4021]
List-ID mail [RFC4021]
List-Owner mail [RFC4021]
List-Post mail [RFC4021]
List-Subscribe mail [RFC4021]
List-Unsubscribe mail [RFC4021]
Message-Context mail [RFC4021]
Message-ID mail standard [RFC5322]
Message-Type mail [RFC4021]
MMHS-Exempted-Address mail [RFC6477][ACP123 Appendix A1.1 and Appendix B.105]
MMHS-Extended-Authorisation-Info mail [RFC6477][ACP123 Appendix A1.2 and Appendix B.106]
MMHS-Subject-Indicator-Codes mail [RFC6477][ACP123 Appendix A1.3 and Appendix B.107]
MMHS-Handling-Instructions mail [RFC6477][ACP123 Appendix A1.4 and Appendix B.108]
MMHS-Message-Instructions mail [RFC6477][ACP123 Appendix A1.5 and Appendix B.109]
MMHS-Codress-Message-Indicator mail [RFC6477][ACP123 Appendix A1.6 and Appendix B.110]
MMHS-Originator-Reference mail [RFC6477][ACP123 Appendix A1.7 and Appendix B.111]
MMHS-Primary-Precedence mail [RFC6477][ACP123 Appendix A1.8 and Appendix B.101]
MMHS-Copy-Precedence mail [RFC6477][ACP123 Appendix A1.9 and Appendix B.102]
MMHS-Message-Type mail [RFC6477][ACP123 Appendix A1.10 and Appendix B.103]
MMHS-Other-Recipients-Indicator-To mail [RFC6477][ACP123 Appendix A1.12 and Appendix B.113]
MMHS-Other-Recipients-Indicator-CC mail [RFC6477][ACP123 Appendix A1.12 and Appendix B.113]
MMHS-Acp127-Message-Identifier mail [RFC6477][ACP123 Appendix A1.14 and Appendix B.116]
MMHS-Originator-PLAD mail [RFC6477][ACP123 Appendix A1.15 and Appendix B.117]
MT-Priority mail standard [RFC6758]
Obsoletes mail [RFC4021]
Organization mail informational [RFC7681]
Original-Encoded-Information-Types mail [RFC4021]
Original-From mail standard [RFC5703]
Original-Message-ID mail [RFC4021]
Original-Recipient perm/original-recipient mail standard [RFC3798][RFC5337]
Originator-Return-Address mail [RFC4021]
Original-Subject mail standard [RFC5703]
PICS-Label mail [RFC4021]
Prevent-NonDelivery-Report mail [RFC4021]
Priority mail [RFC4021]
Received mail standard [RFC5322][RFC5321]
Received-SPF mail standard [RFC7208]
References mail standard [RFC5322]
Reply-By mail [RFC4021]
Reply-To mail standard [RFC5322]
Require-Recipient-Valid-Since mail standard [RFC7293]
Resent-Bcc mail standard [RFC5322]
Resent-Cc mail standard [RFC5322]
Resent-Date mail standard [RFC5322]
Resent-From mail standard [RFC5322][RFC6854]
Resent-Message-ID mail standard [RFC5322]
Resent-Reply-To mail obsoleted [RFC5322]
Resent-Sender mail standard [RFC5322][RFC6854]
Resent-To mail standard [RFC5322]
Return-Path mail standard [RFC5322]
Sender mail standard [RFC5322][RFC6854]
Sensitivity mail [RFC4021]
Solicitation mail [RFC3865]
Subject mail standard [RFC5322]
Supersedes mail [RFC4021]
To mail standard [RFC5322]
VBR-Info mail standard [RFC5518]
X400-Content-Identifier mail [RFC4021]
X400-Content-Return mail [RFC4021]
X400-Content-Type mail [RFC4021]
X400-MTS-Identifier mail [RFC4021]
X400-Originator mail [RFC4021]
X400-Received mail [RFC4021]
X400-Recipients mail [RFC4021]
X400-Trace mail [RFC4021]

block outgoing smtp(25/tcp)

iptables -A OUTPUT ! -d -p tcp --dport 25 -j REJECT

delete queued mails

\rm -r /var/spool/mqueue/*
/etc/init.d/sendmail stop ; mv /var/spool/mqueue{,.bak} ; mkdir /var/spool/mqueue ; chown root:mail /var/spool/mqueue ; chmod 700 /var/spool/mqueue ; /etc/init.d/sendmail start

sendmail in debug mode.

Edit sendmail config.

vim /etc/mail/

Change line to:

define(`confLOG_LEVEL', `15')dnl

Apply change to config.


sendmail via local tunnel Have tunnel running like this: ssh

define(`SMART_HOST', `[localhost]')dnl
define(`RELAY_MAILER', `esmtp')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl

Multiple smart hosts in sendmail