this post was submitted on 09 Jan 2024
6 points (71.4% liked)

Python

6380 readers
112 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

cross-posted from: https://beehaw.org/post/10863052

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: [email protected]
250 OK
rcpt to: [email protected]
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
top 6 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 10 months ago (1 children)

Use mailx along with a .mailrc file? Once .mailrc is set up it should just need:

$ echo 'is this working?' | mailx -s Test

Not sure exactly what .mailrc needs for gmail but there are tons of guides out there.

[–] [email protected] 2 points 10 months ago

Mailx is exactly what I use to send email from servers for cron jobs. Works great.

[–] [email protected] 3 points 10 months ago (1 children)

yes, i use mutt for this purpose. since most email addresses these days will only accept mail from a validated email server, you can hard code your email creds into mutt to send the email 'from' many email providers, including gmail

[–] dbx12 1 points 10 months ago

I want to add that Gmail is a bit of a dick when it comes to SMTP.

[–] [email protected] 3 points 10 months ago

Yes, you can. Python has Email package to manage email through STMP protocol. I use it daily in my scripts. Attached link is a tutorial of Real Python:

https://realpython.com/python-send-email/

[–] [email protected] 1 points 10 months ago

SMS obviously won't be free, aside from the aforementioned email solution, what about other services such as Discord/Teams/Slack?

Sending a message via any of them is rather trivia - Discord has a webhook API as well as a python wrapper.

Me and the SO have our own server and individual channels for ourselves where I use some webhooks to post stuff from Home Assistant for notifications