SendEmail with Time

I am trying to send an email that includes the time. It seems that if the message field includes a colon the message field in the email will be blank.
If I do:
x=datetime.datetime.now()
message=x.strftime(code)
sendEmaiI(‘a@b.com’,‘subject’,message)

The following will show the correct text in the message field:
strftime(%a)
strftime(%w)
strftime(%b)
etc.
But if I use the following, no text will show in the message:
strftime(%c)
strftime(%X)

In fact
strftime(“%b %d %-I " + “/”+” %-M %p")
will have the message, Feb 11 8 / 48 PM
but
strftime(“%b %d %-I " + “:”+” %-M %p")
will have a blank message
The only difference being a “:” instead of “/”

I’m not sure what your sendEmail() is doing but the all appear to work fine on my WSL:

In [5]: now.strftime('%b %d %-I / %-M %p')
Out[5]: 'Feb 11 8 / 6 PM'

In [6]: now.strftime('%b %d %-I : %-M %p')
Out[6]: 'Feb 11 8 : 6 PM'

In [7]: now.strftime('%c')
Out[7]: 'Sat Feb 11 20:06:23 2023'

In [8]: now.strftime('%X')
Out[8]: '20:06:23'

I’m guessing the issue is with sendEmail()

I agree but why does a colon create such a problem?

You would need to provide the implementation details for sendEmail() for us to be able to try to see.

These are the imports

import sys
import pigpio
import _433
import paho.mqtt.client as mqtt
from operator import itemgetter
import time, socket
from datetime import datetime, timedelta
import smtplib

Here is the function: (a@b.com is a dummy for my real account)

def sendEmail(recipient,subject,message):   
    s = smtplib.SMTP('smtp.gmail.com', 587)
    s.starttls()
    s.login("a@b.com", "blanked out")
    s.sendmail("a@b.com.com@gmail.com", recipient, f"Subject: {subject}\n{message}")
    s.quit()

Results of some more testing:
If the message is just, “some text” it will be received.
If the message is, “some text”+“:”
(That is a colon in the +“:”)
The received message field will be blank
If the message is, “some text+”;"
(That is a semicolon in the +“;”)
All the characters will be in the received message field

Now for the kicker. I am using the exact same code in another script and it works fine.

Odd. The only thing i can think of is maybe some encoding messes with it?

Try this:

import smtplib

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

    with smtplib.SMTP('smtp.gmail.com', port=587) as smtp:
        smtp.starttls()
        smtp.login(<user>, <password>)

        msg_mime = MIMEMultipart("alternative")
        msg_mime["Subject"] = <subject>
        msg_mime["From"] = <sender>
        msg_mime["To"] = <to>
        msg_mime.attach(MIMEText(<msg content>, "plain"))

        return smtp.sendmail(sender, [to], msg_mime.as_string())

Hopefully it works… otherwise I’m out of ideas.