# Can you send email using sendmail?



## asys (Jun 2, 2017)

First of all, I'm sorry if the title is confusing or doesn't make any sense but I'm simply confused by the intricacies of this whole email technology. I read somewhere that you can send email using `sendmail -it < mail` but it only goes as far as the queuing list. I've formatted the mail file as below:

```
To: someemail@gmail.com
Subject: foobar
Mime-Version: 1.0
Content-Type: text/plain

Sample line
```

Can this actually be done on a machine from a home network or does it involves something else?


----------



## ShelLuser (Jun 2, 2017)

Look into mail(1) instead.

So going for your example above:

`echo "Sample line" | mail -s foobar someemail@gmail.com`, and done.


----------



## asys (Jun 3, 2017)

I'm afraid the mail is still stuck in the queue with message Deffered: Operation timed out with alt4.gmail-smtp.in.1.google.com. Did I messed up some configuration or something? Mind you i'm doing this on a personal machine from a home network with same made up domain name if that somehow be the reason none of this works.


----------



## ShelLuser (Jun 3, 2017)

First of all that hostname sounds quite weird to me, not sure how you came up with that one but it doesn't exist. These are the servers which handle GMails incoming e-mail:


```
;; QUESTION SECTION:
;gmail.com.                     IN      MX

;; ANSWER SECTION:
gmail.com.              1090    IN      MX      30 alt3.gmail-smtp-in.l.google.com.
gmail.com.              1090    IN      MX      20 alt2.gmail-smtp-in.l.google.com.
gmail.com.              1090    IN      MX      10 alt1.gmail-smtp-in.l.google.com.
gmail.com.              1090    IN      MX      5 gmail-smtp-in.l.google.com.
gmail.com.              1090    IN      MX      40 alt4.gmail-smtp-in.l.google.com.
```
But assuming that this was a typo then yeah: there's always a chance that some mailservers will refuse to accept e-mail from random hosts. Best way to check up on this is the mail logfile: /var/log/maillog.


----------



## asys (Jun 5, 2017)

ShelLuser said:


> But assuming that this was a typo then yeah: there's always a chance that some mailservers will refuse to accept e-mail from random hosts. Best way to check up on this is the mail logfile: /var/log/maillog.



You're right. I mistyped the hostname. The stat field from /var/log/maillog are all filled with Deffered: Operation timed out with alt4.gmail-smtp-in.1.google.com. I've sent a handful of emails by now but none made it past the server. I guess the mailserver won't accept some stray mail after all.

A little bit off topic here, would you be so kind to point me to any guide for setting up a local mailserver? The simplest one would do.


----------



## drhowarddrfine (Jun 5, 2017)

They moved their links around so this isn't the helpful one I was going to give you but somewhere on that site should be documentation for sendmail. There are tons of tutorials around including setting up sendmail on FreeBSD including a brief "gets you running" in the FreeBSD handbook.


----------



## ekingston (Jun 5, 2017)

If I remember correctly, Google has some pretty strict rules about the sources they allow incoming email from. For example, I _think_ Google's receivers reject email from IP addresses that are identified as consumer DHCP allocated. I know they watch for open relays and reject everything coming from those they identify.

If you point your sendmail config to your ISPs outbound relay servers, you may have better luck.


----------



## ronaldlees (Jun 6, 2017)

ekingston said:


> If I remember correctly, Google has some pretty strict rules about the sources they allow incoming email from. For example, I _think_ Google's receivers reject email from IP addresses that are identified as consumer DHCP allocated. I know they watch for open relays and reject everything coming from those they identify.
> 
> If you point your sendmail config to your ISPs outbound relay servers, you may have better luck.



Yeah - gone are the days when I could direct-send any email with telnet :-(  Back in the day, a lot of servers even facilitated this with long timeouts on commands.  No more.   A  few bad apples ...


----------



## drhowarddrfine (Jun 7, 2017)

ekingston said:


> Google has some pretty strict rules about the sources they allow incoming email from.


Everybody has strict rules, not just Google, and you can forget getting accepted by anything Microsoft runs. 

You need to set up SPF and DKIM using a real domain name with a static IP but that can get you into GMail and Yahoo. Our small clients have never broken through Outlook or Live or any of that other Microsoft stuff.


----------

