EDIT: Thanks y’all! I got this working by installing mutt and configuring it with my Gmail info. Please note the warning from u/jherazob below–if this were something mission critical I would not want to rely on this solution.

================

Noob question incoming, thanks in advance for any help with this!

I have a specific use case in which I want to send an automated email or text to myself once a day (the message is different each time–otherwise I would just set an alarm, lol!). I’m running Pop_OS on an old desktop computer. Where I’m stuck is getting an email to successfully send from the command line. I’m looking for easy-to-follow instructions that would help me do that, and none of the articles or videos I’ve come across thus far have helped.

I’m aware of Twilio and other services that send SMS messages, but I’m looking for something free. Especially since I only need to text one person (myself), and infrequently at that.

Below is my attempt to send an email with the telnet command. Nothing ever came through…

XXXXXXXX@pop-os:~$ telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 pop-os ESMTP Exim 4.95 Ubuntu Sun, 07 Jan 2024 15:12:28 -0500
HELO gmail.com
250 pop-os Hello localhost [::1]
mail from: XXXXXXXX@gmail.com
250 OK
rcpt to: XXXXXXXX@gmail.com
250 Accepted
data
354 Enter message, ending with "." on a line by itself
Subject: Test
Body: Is this working?
.
250 OK id=1rMZW4-0002dj-Uy
quit
  • Radiant_sir_radiant@beehaw.org
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    8 months ago

    I see several issues with your SMTP session.

    First, gmail.com will be protected by SPF and DKIM and your message will likely be flagged as spam (or outright rejected) because it’s clear that you’re not sending on behalf of the real gmail.com.

    Second, commands should be in all-caps. A server may accept or reject lowercase keywords.

    Third, you need to leave a blank line between the mail headers and the body, so that part of your session would look like so: …

    DATA
    354 Go ahead
    From: ...
    To: ...
    Subject: ...
    
    This is the first line of text.
    This is the second line.
    .
    250 Queued
    

    Having said that, many servers will require an encrypted connection (SMTPS), many ISPs will block port 25 for residential customers as an anti-spam measure (so your local mail server may accept the message from your script but be unable to forward it), ESMTP should be preferred over SMTP etc.
    If at all possible, you should use a full-featured mail library for this and use your ISP’s own mail server.

    Doesn’t Pop_OS come with a sendmail command?

  • ono@lemmy.ca
    link
    fedilink
    English
    arrow-up
    3
    ·
    edit-2
    8 months ago

    Your current approach of talking raw SMTP is likely to be more hassle than is worthwhile, and since the days of permissive SMTP servers are long gone, might not work at all.

    Since you appear to be using an Debian-based Linux distro, I suggest this approach:

    • If you don’t specifically need exim, consider replacing it with the lightweight dma package (DragonFly Mail Agent): apt install dma
    • Configure dma (or exim) to use your ISP’s SMTP server as a smart host. (Or the Gmail SMTP server if your ISP doesn’t provide one.)
    • Use the /usr/sbin/sendmail command (which comes with dma or exim) to send messages from your scripting language of choice.

    If you prefer to receive messages as SMS, note that most major mobile carriers maintain an email-to-sms gateway for this purpose. Some web searches will probably lead you to the one for your carrier. They usually accept email at an address like 123456789@sms-gateway.example.com

  • Fal@yiffit.net
    link
    fedilink
    English
    arrow-up
    3
    ·
    8 months ago

    You could probably do something with tasker to create these daily notifications

    • friendly_ghost@beehaw.orgOP
      link
      fedilink
      arrow-up
      1
      ·
      8 months ago

      Ah, you mean run the script directly on the phone without involving the desktop computer? I hadn’t considered that but it’s a great suggestion. Thanks!

  • flatbield@beehaw.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    edit-2
    8 months ago

    Many cell providers have a mail to SMS gateway. Just sent email to the correct address and you’ll get SMS. As far as sending mail either with bash or with Python. That is quite possible and not hard.

    Sorry I do not have the code at hand. Memory is Python standard library has SMTP capability and Bash you can just use the mail command. May have to configure mail on your Linux box too or just use a remote server.