# sending mail from terminal



## sk8harddiefast (Jul 23, 2010)

Is any tool to send mails from terminal?
Also i have a tool named mail.
Can this do the job?
I tried it but stack on subject.
I give subject name but is not continuing.
Just stay there an do nothing
For example

```
mail -v ska8harddiefast@gmail.com
Subject: test

ehfd;wefdqwie
eqwejq2po3
jqwepq3
jdpq223e12


dqdeqwd
```

After test & enter understand everything i write but is not going to the section "write the mail"


```
ehfd;wefdqwie
eqwejq2po3
jqwepq3
jdpq223e12


dqdeqwd
```
This is not the mail. Is the continue of subject :OOO


----------



## rusty (Jul 23, 2010)

Ctrl+D when finished, that pushes it off to the send queue.


----------



## sk8harddiefast (Jul 23, 2010)

I tried that and i take this

```
mail -v sk8harddiefast@gmail.com
Subject: test
^DEOT
Null message body; hope that's ok
sk8harddiefast@gmail.com... Connecting to [127.0.0.1] via relay...
220 bsdserver.bsd ESMTP Sendmail 8.14.3/8.14.3; Fri, 23 Jul 2010 14:33:04 +0300 (EEST)
>>> EHLO bsdserver.bsd
250-bsdserver.bsd Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<deadreamer@bsdserver.bsd> SIZE=44
250 2.1.0 <deadreamer@bsdserver.bsd>... Sender ok
>>> RCPT To:<sk8harddiefast@gmail.com>
>>> DATA
250 2.1.5 <sk8harddiefast@gmail.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 o6NBX4wh020798 Message accepted for delivery
sk8harddiefast@gmail.com... Sent (o6NBX4wh020798 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 bsdserver.bsd closing connection
```


----------



## SirDice (Jul 23, 2010)

Put a period (.) on an empty line. That tells mail to stop.


----------



## sk8harddiefast (Jul 23, 2010)

```
Put a period (.) on an empty line. That tells mail to stop.
```
I take the same result


----------



## DutchDaemon (Jul 23, 2010)

```
$ mail -v -s "The subject goes here" someone@somewhere.net [enter]                                                              
Hey, how's it going? [enter]
. [enter]
```

That's all.


----------



## DutchDaemon (Jul 23, 2010)

You can also put the body of the email in a text file, and run:


```
cat textfile | mail -v -s "Some subject" somewhere@somewhere.net [enter]
```

The end of the textfile will cause the EOT and send the mail.


----------



## sk8harddiefast (Jul 24, 2010)

I take this:

```
You have new mail in /var/mail/deadreamer
```
But why here? I gave my gmail. Logical shouldn't be sent on my gmail account?


----------



## DutchDaemon (Jul 24, 2010)

You're probably seeing a bounce? You need a valid sender address to get it accepted anywhere.


----------



## sk8harddiefast (Jul 25, 2010)

```
You need a valid sender address to get it accepted anywhere
```
I give my email address. Is a valid address.
I take exactly this

```
mail -v -s test sk8harddiefast@ %&#$%^^.com [enter]
Hi. My name is George [enter]
.[enter]
EOT
sk8harddiefast@ %&#$%^^.com... Connecting to [127.0.0.1] via relay...
220 bsdserver.bsd ESMTP Sendmail 8.14.3/8.14.3; Sun, 25 Jul 2010 11:44:20 +0300 (EEST)
>>> EHLO bsdserver.bsd
250-bsdserver.bsd Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<deadreamer@bsdserver.bsd> SIZE=66
250 2.1.0 <deadreamer@bsdserver.bsd>... Sender ok
>>> RCPT To:<sk8harddiefast@ %&#$%^^.com>
>>> DATA
250 2.1.5 <sk8harddiefast@ %&#$%^^.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 o6P8iKmq016611 Message accepted for delivery
sk8harddiefast@ %&#$%^^.com... Sent (o6P8iKmq016611 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 bsdserver.bsd closing connection
```
Seems to be ok. But i don't see any mail on my $^#%$^& account :OOO


----------



## Beastie (Jul 25, 2010)

If you don't want to get spam in your inbox, I suggest you remove your address from your posts.

As for your problem, maybe the message has not been sent yet. Check the queue with mailq(1).


----------



## sk8harddiefast (Jul 25, 2010)

> If you don't want to get spam in your inbox, I suggest you remove your address from your posts.


I think you have right. Thanks!


----------



## DutchDaemon (Jul 25, 2010)

Look in your maillog. If you are sending with the *.bsd domain, it won't be accepted anywhere (except localhost, maybe) as it is not a valid Internet domain.


----------



## sk8harddiefast (Jul 25, 2010)

> Look in your maillog. If you are sending with the *.bsd domain, it won't be accepted anywhere (except localhost, maybe) as it is not a valid Internet domain.


Where is maillog?
What i should do? I have completely no idea :/


----------



## FrogLS (Jul 25, 2010)

sk8harddiefast said:
			
		

> Where is maillog?



/var/log/maillog

You can also always deploy find(1)() if you are not
sure where to look for certain files or directories.


----------



## Martin Paredes (Oct 26, 2018)

sk8harddiefast said:


> I take this:
> 
> ```
> You have new mail in /var/mail/deadreamer
> ...


When you send the mail, you use your local user mail to send the mail to your account in GMail

The mail you received locally, is maybe a notification of a reject by the GMail server and what caused (in this case your local address isn't valid in Internet)

What you may be looking is in the Handbook, in the section Setting Up to Send Only (the use of mail/ssmtp)


----------



## SirDice (Oct 26, 2018)

Martin Paredes you are responding to an 8 year old thread.


----------



## SAJM (Feb 25, 2021)

WOW!!!! This thread takes me back to the 80s with BY Telecom Gold and cix.compulink.

Sending emails and newsgroups on text based systems where attacments required a great deal of thought, We could even send telexs on Telecom Gold.

I though I was so smart and leading edge back then.


----------



## drhowarddrfine (Feb 25, 2021)

SAJM Hm. For a lot of us, it was this morning or, for me, a few minutes ago. And every day. Is there a problem with that?


----------



## SAJM (Feb 25, 2021)

drhowarddrfine said:


> SAJM Hm. For a lot of us, it was this morning or, for me, a few minutes ago. And every day. Is there a problem with that?


I think you have misunderstood my reminiscing.


----------



## drhowarddrfine (Feb 25, 2021)

Possibly so.


----------



## zirias@ (Feb 25, 2021)

SAJM said:


> Sending emails and newsgroups on text based systems where attacments required a great deal of thought


Seriously, try (neo)mutt. I still use it as my daily mail driver. Sure, sometimes you receive a mail THAT braindead (e.g. including links, but not in the text/plain part, or this part is missing altogether) to make it a little hassle. But most of the time, there's nothing quicker and more efficient than a good MUA on the console.


----------



## SAJM (Feb 25, 2021)

drhowarddrfine said:


> Possibly so.


Not too many people use emails from the command prompt now. 
Telex is gone as I think are Newsgroups.
All those years ago.


----------



## drhowarddrfine (Feb 25, 2021)

SAJM said:


> Not too many people use emails from the command prompt now.


Hmm. I will alert the crew.


----------



## SAJM (Feb 25, 2021)

Zirias said:


> Seriously, try (neo)mutt. I still use it as my daily mail driver. Sure, sometimes you receive a mail THAT braindead (e.g. including links, but not in the text/plain part, or this part is missing altogether) to make it a little hassle. But most of the time, there's nothing quicker and more efficient than a good MUA on the console.


Looking up mutt now.


----------



## zirias@ (Feb 25, 2021)

SAJM said:


> Not too many people use emails from the command prompt now.
> Telex is gone as I think are Newsgroups.


Well, I kind of agree on Telex.


----------



## SAJM (Feb 25, 2021)

neomutt doesn't load


----------



## scottro (Feb 25, 2021)

I prefer neomutt these days, but to be honest, for me, I don't see much difference between it and mutt. I have a mutt page https://srobb.net/mutt.html that goes into some details of setting up sending and receiving, though these days, even mutt has grown, to the point where it can send and receive on its own, though I still prefer getmail and msmtp (especially the latter, as I send on different email addresses.)

The trouble is that while the good doctor is right, about lots of people using it, it's all the ones who don't that are the problem. Jason Ryan of ArchLinux has one of my favorite articles about it, which also includes a way to view those mails that are html only in mutt. (That is, the REALLY stupid ones where links won't show in say, w3m.)  https://www.jasonwryan.com/blog/2012/05/12/mutt/

Depending upon your position and such, many of us aren't in a position to tell our boss, Look you foolish person, if you wish me to waste my time reading your undoubtedly unnecessary email, send it in plain text.  So, most of us, even those who use good mail clients like neomutt, often have to read this stupid html email, which should have never been allowed. Even now, with ISPs bribing politicians to get bandwidth limits---oh, let me shut up, or I'll go on and on and...  (That last one may just be a US problem, most other developed countries seem to have competition for Internet, so that the ISPs have to offer something decent. In the US it's.....
Heh, another rather old youtube video describes it well. (Obscenity in the video).




_View: https://www.youtube.com/watch?v=0ilMx7k7mso_


----------



## zirias@ (Feb 25, 2021)

scottro said:


> a way to view those mails that are html only in mutt.


Got this for long since, even hacked it a bit to work around other weird problems I since forgot, I got these in my ~/.mailcap:

```
text/html;w3m -cols 72 -I %{charset} -T text/html -s | sed -e 's:^[[:blank:]]*$::' | cat -s; copiousoutput
application/msword;catdoc -a %s; nametemplate=%s.doc; copiousoutput
application/rtf;catdoc -a %s; nametemplate=%s.rtf; copiousoutput
```

But it won't help with links in html-only mails when the caption is not the link itself, w3m processing into text will only show the caption. So in these rare cases, you have to dig into the "source"…

Of course, a *sane* HTML email always is mime/multipart, including a text/plain part which has the links in plaintext. But yes, every now and then, you receive a braindead broken Email.


----------



## SAJM (Feb 25, 2021)

SAJM said:


> neomutt doesn't load


Ive got this pesky

Creating user '_tss' with uid '601'.
pw: user '_tss' disappeared during update

problem. It seems to pop up all the time

I will deal with it tomorrow


----------



## hruodr (Feb 25, 2021)

sk8harddiefast said:


> Is any tool to send mails from terminal?


If you want to send mail with the command `mail`, you must configure `sendmail`
in order that other  MTA accept mail from it. Without a static IP and a MX entry you will perhaps not get it, 
unless configuring it as SMARTHOST for authenticating to other MTA, for example to your gmail account, 
and sending from there, as were `sendmail` a MUA, to do it is only a little configuration work, 
but doable. But for reading then your gmail account you must get the emails with something like 
`fetchmail`.

It is simpler to use a program like `alpine` to authenticate to gmail and read gmail with imap.
Its support for imap is better than the one of mutt. And you can use it for reading and writing to usenet.


----------



## richardtoohey2 (Feb 25, 2021)

SAJM said:


> pw: user '_tss' disappeared during update
> 
> problem. It seems to pop up all the time


I _think_ I've seen that a proper fix is in the works.

But to manually address: https://forums.freebsd.org/threads/...-disappeared-during-update.59525/#post-341447


----------



## BobSlacker (Dec 22, 2022)

I would like to use this script with a cronjob but instead of send to the root mailbox I wold like to send to my actual email. Is that possible without a static ip address?


----------



## covacat (Dec 22, 2022)

the base system sendmail wont do
you need another mta or compile base sendmail with cyrus sasl support
then you can authenticate to your mail provider mta
hopefully not google because that is a pain


----------



## BobSlacker (Dec 22, 2022)

covacat said:


> the base system sendmail wont do
> you need another mta or compile base sendmail with cyrus sasl support
> then you can authenticate to your mail provider mta
> hopefully not google because that is a pain


Thank you for your reply.
I use ProtonMail. Can you recommend me a MTA? Please.


----------



## richardtoohey2 (Dec 22, 2022)

BobSlacker said:


> Thank you for your reply.
> I use ProtonMail. Can you recommend me a MTA? Please.


Have you tried it?  It might work (or it might with some tweaking).


```
mail -s "My test email" test@test.com
the body here
.
EOT
```

So I typed the first line, the mail program waits for me to type a messge, then . on a line by itself means end of message (mail shows EOT for End Of Text I'm assuming.)

Obviously change test@test.com to an email address where you really DO want to get the email - see if it arrives, look in your Spam, check /var/log/maillog.

In my case it's a no-go:


```
dsn=4.3.0, reply=451-p.q.r.s is not yet authorized to deliver mail from
```


----------



## covacat (Dec 23, 2022)

many IPSs block outgoing port 25, many mail hostings reject residential IP ranges, or/and reject mail from IPs without reverse DNS mapping unless they are authenticated
I personally use base sendmail compiled with SASL support but it's not ideal (need to recompile sendmail after freebsd-update)


----------



## facedebouc (Dec 23, 2022)

covacat said:


> many IPSs block outgoing port 25, many mail hostings reject residential IP ranges, or/and reject mail from IPs without reverse DNS mapping unless they are authenticated
> I personally use base sendmail compiled with SASL support but it's not ideal (need to recompile sendmail after freebsd-update)


mail/sendmail package is compiled with SASL. I am using it for my own mail server in replacement of base sendmail.


----------



## covacat (Dec 23, 2022)

facedebouc said:


> mail/sendmail package is compiled with SASL. I am using it for my own mail server in replacement of base sendmail.


this is the better approach im just kind of stuck in the past for no really good reason


----------



## hruodr (Dec 23, 2022)

BobSlacker said:


> I would like to use this script with a cronjob but instead of send to the root mailbox I wold like to send to my actual email. Is that possible without a static ip address?


If you want to send mail from a script, you will call an email client in the script.
It is not a good Idea to call mozilla thunderbird in a script. Better are traditional
command line programs like sendmail or mailx that calls sendmail. For that, you need
to configure sendmail as a client (SMART HOST) that is able to connect to
your email provider and send the mail from there.

Unfortunately it is not anymore possible to configure sendmail with google due xoath2,
but there are lots of free smtp mail providers that you can log in with a password,
for example web.de, and from there you can send mails to your  ProtonMail account.

Here is a link to configure sendmail:









						mail, metamail, gpg, openssl, sendmail, fetchmail, etc AS MAIL CLIENT
					

This thread is dedicated to simple command line tools as mail client for normal desktop users, in order to show that FreeBSD has a past and a future as desktop system.  My contribution is to configure sendmail as smart host, in order that one can use normal mail to send mails. Perhaps someone...




					forums.freebsd.org
				




You can also use a program like this:






						msmtp - Wikipedia
					






					en.wikipedia.org


----------



## chrbr (Dec 23, 2022)

BobSlacker said:


> I use ProtonMail. Can you recommend me a MTA? Please.


I like mail/opensmtpd because it is easy to configure, at least for my use case.


----------



## Ogis (Dec 23, 2022)

SAJM said:


> neomutt doesn't load


Neomutt and mutt don't work with gmail. Google should be thanked here for its stupid "security" policy.


----------



## scottro (Dec 23, 2022)

They do work with gmail, but it requires extra work.  I use it with msmtp and getmail. I have a short page with explanation, at https://www.srobb.net/gmailgetmail.html. It focuses on using getmail and msmtp with mutt, but it should be adaptable.


----------



## fjdlr (Dec 23, 2022)

I'm using`mail` system (console) for local and WAN.
On console, `mutt`or `neomutt`
I'm using postfix for send mail and `fetchmail`for retry mails
SASL protocol for password on server FAI
I define smarthost and aliases in mailer.conf
After `freebsd-upgrade` "`service stop and start postifx`"


----------

