Sendmail: Difference between revisions

From Halfface
Jump to navigation Jump to search
Line 358: Line 358:
  define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl
  define(`RELAY_MAILER_ARGS', `TCP $h 2525')dnl
=Multiple smart hosts in sendmail=
=Multiple smart hosts in sendmail=
  define(SMARTHOST `[realmailserver1.yourdomain.com]:[realmailserver2.yourdomain.com]')
  define(`SMART_HOST',`host1:host2:host3')
 
[[Category:Applications]]
[[Category:Applications]]
[[Category:Unix]]
[[Category:Unix]]

Revision as of 15:44, 26 April 2019

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 hotmail.com

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 smtp.domain.com 25
Trying 192.168.0.1...
Connected to smtp.domain.com (192.168.0.1).
Escape character is '^]'.
220 myrelay.domain.com ESMTP
HELO smtp.domain.com
250 myrelay.domain.com
MAIL FROM:<alice@hacker.com>
250 sender <alice@hacker.com> ok
RCPT TO:<bob@secure.net>
250 recipient <bob@secure.net> ok
DATA
354 go ahead
From: [Alice Hacker] <alice@hacker.com>
To: [Bob Smith] <bob@secure.net>
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!
Alice


.
250 ok:  Message 222220902 accepted
QUIT
221 myrelay.domain.com
Connection closed by foreign host.

send mail via telnet and expect

#!/usr/bin/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"
                exit    
        } "2?? *" {
        } "4?? *"   {
                exit
        } "refused" {
                send_user "$mailserver: connect refused\n"
                exit
        } "closed" {
                send_user "$mailserver: connect closed\n"
                exit
        } timeout {
                send_user "$mailserver: connect to port 25 timeout\n"
                exit
        }
send "HELO foo.com\r"
expect "2?? *" {
} "5?? *" {
        exit
} "4?? *" {
        exit
}
send "MAIL FROM: <$from>\r"
expect "2?? *"  {
} "5?? *" {
        exit
} "4?? *" {
        exit
}
send "RCPT TO: <$to>\r"
expect "2?? *" {
} "5?? *" {
        exit
} "4?? *" {
        exit
}
send "DATA\r"
expect "3?? *" {
} "5?? *" {
        exit
} "4?? *" {
        exit
}
send "From: $from\r"
send "To: $to\r"
send "Subject: test\r"
send "This is a test message\r"
send ".\r"
expect "2?? *" {
} "5?? *" {
        exit
} "4?? *" {
        exit
}
send "QUIT\r"
exit

SMTP servers for internet providers

mailrelay.bostream.com 		smtp
smtp.bredband.net		smtp

smarthost

set smarthost and domain. /etc/mail/sendmail.mc define(`SMART_HOST', `smtp.bredband.net')

LOCAL_DOMAIN(`www.halfface.se')dnl

sendmail listen on all network interfaces

Enable smtp on all interfaces.

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

Usermappings

/etc/mail/virtusertable

anden@halfface.se bjorklun andreas.bjorklund@halfface.se bjorklun stannaks@halfface.se stannaks none@halfface.se error:nouser 550 No such user here wrong@halfface.se error:5.7.0:550 Address invalid @halfface.se bjorklun anna-karin@sivberg.se stannaks @sivberg.se stannaks @mobbad. bjorklun @anden.homeip.net bjorklun


aliases for your host

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

anden.homeip.net www.halfface.se halfface.se www.mobbad.nu mobbad.nu www.sivberg.se sivberg.se


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

<verbatim> /etc/mail/access

localhost.localdomain RELAY localhost RELAY 127.0.0.1 RELAY 192.168.2.1 RELAY 192.168.3.1 RELAY AuthInfo:smtp.bredband.net "U:b586378" "I:b586378" "P:??????" "M:LOGIN PLAIN"


Forward a copy of email.

~/.forward

\bjorklun andreas.bjorklund@infineon.com

sending mail from command line

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

Andreas Bjorklund doing test. anden@halfface.se

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

explained

   2.1.2. Header Field: From

   Description:  
       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

   Description:  
       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

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

envelope-from

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 127.0.0.1 -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/sendmail.mc

Change line to:

define(`confLOG_LEVEL', `15')dnl

Apply change to config.

/etc/mail/make

sendmail via local tunnel

sendmail.mc. Have tunnel running like this: ssh -L2525:smtp.host.com:25 host.access.com

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

Multiple smart hosts in sendmail

define(`SMART_HOST',`host1:host2:host3')