Solved sending mail via mail / mailx

also this is not really new because if you look at my sendmail.mc file you can see that I configured it for port 587 but I still found your question useful and it helps the community as well as myself for now or in a future setup... or maybe to look back and see oh what a piece of cake this was...
 
root@kaufland.de:/etc/mail # echo "Test body" | mail -v -s "Test Subject" paul@kaufland.de
echo: not found
Null message body; hope that's ok
paul@kaufland.de... Connecting to [127.0.0.1] via relay...
220 kaufland.de ESMTP Sendmail 8.18.1/8.18.1; Thu, 18 Dec 2025 19:11:06 -0500 (EST)
>>> EHLO kaufland.de
250-kaufland.de Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-STARTTLS
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> STARTTLS
220 2.0.0 Ready to start TLS
>>> EHLO kaufland.de
250-kaufland.de Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<sixpiece@kaufland.de> SIZE=41
250 2.1.0 <sixpiece@kaufland.de>... Sender ok
>>> RCPT To:<paul@kaufland.de>
>>> DATA
050 <paul@kaufland.de>... aliased to sixpiece
250 2.1.5 <paul@kaufland.de>... Recipient ok
354 End data with <CR><LF>.<CR><LF>
>>> .
050 sixpiece... Connecting to local...
050 220 kaufland.de LMTP ready
050 >>> LHLO kaufland.de
050 250-kaufland.de
050 250-8BITMIME
050 250-ENHANCEDSTATUSCODES
050 250 PIPELINING
050 >>> MAIL From:<sixpiece@kaufland.de>
050 250 2.5.0 Ok
050 >>> RCPT To:<sixpiece>
050 >>> DATA
050 250 2.1.5 Ok
050 354 Go ahead
050 >>> .
050 250 2.1.5 sixpiece Ok
050 sixpiece... Sent
250 2.0.0 5BJ0B637003562 Message accepted for delivery
paul@kaufland.de... Sent (5BJ0B637003562 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 kaufland.de closing connection
a little bit of intermittent progress...
 
# Macros for network interfaces
ext_if = "em0" # Replace with your network interface

# Default policies
set skip on lo # Ignore loopback interface

# Block all incoming by default, allow all outgoing
block in log all
pass out all keep state
I'm checking if it's my firewall because I configured it within the loopback interface...
 
the problem is mostly solved the problem is that there was so many things done that I don't really think I could specifically describe the solution... the part about number 2 I will leave that for another thread, at the end of the day I can send and receive email using mail...
 
there is a mail wrapper, there is another file that was edited on top of pablo.com.mc I changed the hostname to make it less confusing... edited the etc/hosts, firewall wasn't a problem... changed mailer.conf to a different version of sendmail for some reason there are two running one that did stuff and another that wasn't doing things... etc..
 
After wrestling with Sendmail for a bit to get it to play nice with my external SMTP provider, I finally got the "Null Client" setup working. I figured I'd journal the specific steps here in case anyone else is tired of their system mail getting stuck in the queue.

The trick was sticking to the standard /etc/mail workflow and not overcomplicating the .mc file.

What worked for me:​

First, I jumped into /etc/mail and ran make to get my host-specific .mc file. Then, I added the following lines to handle the relay and force port 587 (since my ISP blocks 25):

Code-Snippet

define(`SMART_HOST', `[smtp.yourprovider.com]')dnl<br>FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl<br>define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl<br>define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl<br>

Handling the Auth​

Most providers won't talk to you without credentials. I created /etc/mail/authinfo with:AuthInfo:smtp.yourprovider.com "U:user" "P:password" "M:PLAIN"

Important: Don't forget to run the map and lock down permissions:

Bash

makemap <span>hash</span> authinfo &lt; authinfo<br>chmod 600 authinfo*<br>

The "FreeBSD Way" to Apply​

Instead of manually editing .cf files, just use the built-in Makefile. It's much cleaner:

Bash

make install<br>service sendmail restart<br>

How I verified it​

I kept a terminal open with tail -f /var/log/maillog while running:echo "Test mail" | sendmail -v my-personal@email.com

Seeing the 250 2.0.0 OK in the logs was a beautiful sight. If you're on a laptop and just need your local cron jobs or reports to actually reach your inbox, this seems to be the path of least resistance.
 
what next? consider the options of retrieving emails from multiple different accounts, sending from different accounts and learning the tricks of how to download attachments and how to really get the most of mail. Thank you for your help on this journey ... and I really enjoy reading my email now... and sending them for that matter...
 
I changed my laptop hostname to pablo.com to make it easier and less confusing... there were changes needed in the hosts file and things that were particular like the workplace vpn.. there was a lot of debugging necessary, the order of instructions, watching what was taking place through verbose , analyzing the maillog and fetchmail log for receiving as well as requesting from the webmaster at that time the dovecot logs... there was a command sendmail -bt /tryflags HS and /try esmtp sixpiece and a few other methods I used to test the email and see what was happening witnessing the masquerade... I also had confusion about which file to edit, also read the thread carefully for other things like changing mailer.conf... I will share the files and explain how the sendmail works a bit...

sixpiece@pablo:/etc/mail $ ls
Makefile helpfile pablo.com.mc.1.backup
README kaufland.de.cf pablo.com.mc.bak
access kaufland.de.mc pablo.com.submit.cf
access.db kaufland.de.submit.cf pablo.com.submit.mc
access.sample kaufland.de.submit.mc relay-domains
aliases kaufland.mc sendmail.0.old
aliases.db kaufland.mc.0.old sendmail.cf
authinfo kaufland.mc.1.old sendmail.cf.bak
authinfo.db kaufland.submit.mc sendmail.mc
certs kate.core sendmail.mc.backup.0.1
freebsd.mc local-host-names sendmail.mc.old.1
freebsd.mc.backup mailer.conf submit.cf
freebsd.mc.old.1 mailer.conf.old submit.cf.bak
freebsd.submit.mc mailertable submit.mc
generic-domains mailertable.db virtusertable
generics-domains mailertable.sample virtusertable.db
genericstable new.cf virtusertable.sample
genericstable.db pablo.com.cf
generictable pablo.com.mc


this is the file structure of /etc/mail that I ended up doing... I created a genericstable and generics-domains to be able to masquerade the address that I would be sending the email from. let me share the pablo.com.mc file and hopefully later I will share the genericstable and how that works...

divert(0)
VERSIONID(`$FreeBSD$')
OSTYPE(`freebsd6')dnl
DOMAIN(`generic')dnl

dnl # --- Smart Host & Port 587 Config ---
define(`SMART_HOST', `[mail.kaufland.de]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl

dnl # --- Authentication & TLS ---
FEATURE(`authinfo', `hash -o /etc/mail/authinfo.db')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
TRUST_AUTH_MECH(`EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

dnl # --- Your existing Masquerade & Table Config ---
FEATURE(`access_db', `hash -o /etc/mail/access.db')dnl
FEATURE(`genericstable', `hash -o /etc/mail/genericstable')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
MASQUERADE_AS(`kaufland.de')dnl
FEATURE(`masquerade_envelope')dnl

dnl # --- Mailers (Must stay at the bottom) ---
MAILER(`local')dnl
MAILER(`smtp')dnl
so this order was very important
feature generics table with the access database for the passwords generics domain file masquerading

the authentication more than just plain and this also required the change in mailer.conf whereis sendmail this is unique to freebsd 15 , os type freebsd6
generics-domains
pablo.com
pablo.com.com
there's a lot there and I am not actually per se up to the scruff of knowing every instruction and how everything works it's mammoth obviously but somehow I configured everything to work... hopefully these files help.. when I add the other email address to send from ... receive from should be easy it's just modifying .fetchmailrc sending from different addresses I expect that it will be a command where I specify it but there might be something in sendmail including relay-domains, authinfo and also hopefully the system doesn't break intermittently... internet research using google was helpful... and reading the docs was helpful I think this thread hopefully will simplify it for myself if I ever have to go through this process again which took around 20 hours total to do quite extensive and still not finished. there were other benefits and it definitely did a learning curve but I did have other things at stake ... it's great having this new laptop on freebsd works a charm never had a machine work so great ... and be so much fun as well...
 
things like tabs were important , having ^M characters embedded can cause issues, etc.. there was a lot of technicalities and it was quite the hurdle and every second the solution seemed like it was 20 minutes away...
 
so now I finished the job completely

just a note here is an example of some of the work rebuilding tables and also testing this is a test of an email from paul.heitz@gmail.com sent to paul@kaufland.de the reverse of what I was doing before....

root@pablo:/etc/mail # cd /etc/mail
root@pablo:/etc/mail # makemap hash access < access
root@pablo:/etc/mail # makemap hash genericstable < genericstable
root@pablo:/etc/mail # makemap hash mailertable < mailertable
root@pablo:/etc/mail # makemap hash authinfo < authinfo
root@pablo:/etc/mail # sendmail -v -f "paul.heitz@gmail.com" paul@kaufland.de < /dev/null
test
paul@kaufland.de... Connecting to [127.0.0.1] via relay...
220 pablo.com ESMTP Sendmail 8.18.1/8.18.1; Fri, 19 Dec 2025 08:48:39 -0500 (EST)
>>> EHLO pablo.com
250-pablo.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP
>>> VERB
250 2.0.0 Verbose mode
>>> MAIL From:<paul.heitz@gmail.com> AUTH=paul.heitz@gmail.com
t250 2.1.0 <paul.heitz@gmail.com>... Sender ok
>>> RCPT To:<paul@kaufland.de>
>>> DATA
250 2.1.5 <paul@kaufland.de>... Recipient ok
354 End data with <CR><LF>.<CR><LF>
>>> .
050 <paul@kaufland.de>... Connecting to eu-com-wildcard-null-mx.centralnic.net. via smtp...
050 <paul.heitz@gmail.com>... Connecting to smtp.gmail.com. via smtp...
050 220 smtp.gmail.com ESMTP Postfix
050 >>> EHLO pablo.com
050 250-smtp.gmail.com
050 250-PIPELINING
050 250-SIZE 20480000
050 250-ETRN
050 250-STARTTLS
050 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
050 250-ENHANCEDSTATUSCODES
050 250-8BITMIME
050 250-DSN
050 250 CHUNKING
050 >>> STARTTLS
050 220 2.0.0 Ready to start TLS
050 >>> EHLO pablo.com
050 250-smtp.gmail.com
050 250-PIPELINING
050 250-SIZE 20480000
050 250-ETRN
050 250-AUTH DIGEST-MD5 CRAM-MD5 PLAIN LOGIN
050 250-ENHANCEDSTATUSCODES
050 250-8BITMIME
050 250-DSN
050 250 CHUNKING
050 >>> AUTH PLAIN cGF1bEB2aWRlb3Ryb24uZnIAcGF1bEB2aWRlb3Ryb24uZnIAZDBRZjYwZiU=
050 235 2.7.0 Authentication successful
050 >>> MAIL From:<> SIZE=1325
050 250 2.1.0 Ok
050 >>> RCPT To:<paul.heitz@gmail.com>
050 >>> DATA
050 250 2.1.5 Ok
050 354 End data with <CR><LF>.<CR><LF>
050 >>> .
050 250 2.0.0 Ok: queued as D4700758208A
050 <paul.heitz@gmail.com>... Sent (Ok: queued as D4700758208A)
250 2.0.0 5BJDmdeT003547 Message accepted for delivery
paul@kaufland.de... Sent (5BJDmdeT003547 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 pablo.com closing connection
so there is a mailtertable which I didn''t make use of ... also there is for people maybe even myself a generics table can be configure so that different users have different sending addresses... just a note...
 
just to be clear this project felt extremely difficult and I tried to expand like so I could send mail from different email addresses thinking I just had to make changes to authinfo and it was not so easy... my whole system broke and I had to spend hours diagnosing even felt like the solultion I came up with was different just to get it back to where it was ... I was thinking oh ok I will create a user called frank and let frank use his email on the same relay ... frank@dpt.kaufland.de and that just went sour.. it was confusing... small errors from one type of mail server to the next ESMTP put a . after kaufland.de. and this potentially cause a problem it was extremely difficult yet the system is working so I think I will stop touching it ... I can send email from paul@kaufland.de now and my gmail account so I will leave it at that for now... was it a good decision possibly yes considering I have sendmail servers on cloud maybe it will help familiarize me since there are things not configured well there for example for dmarc or spf sender policy framework they require a txt record on the dns for the ip addresses I will be using so I need to set that and so forth , it's running on open dkim ... nevertheless this has been exhaustive and far more extensive than I planned so I will be satisfied with my accomplishment and leave it at that for now.. thank you for your support... give me a recovery time...
 
Back
Top