问题
I'm trying to figure out how to send SMS messages with custom sender ids from Python. So far, I'm able to send messages from a Gmail account by turning on support for "Less Secure Apps" and running:
import smtplib
import email.mime.multipart
sender = 'douglas.duhaime.messenger@gmail.com'
subject = 'here is the subject'
message = 'cats are on wheels'
recipient = 'MY_NUMBER@tmomail.net'
# Establish a secure session with gmail's outgoing SMTP server using your gmail account
server = smtplib.SMTP('smtp.gmail.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.login(sender, MY_GMAIL_PASSWORD)
msg = '\r\n'.join([
'MIME-Version: 1.0',
'Subject: {}'.format(subject),
'From: {}'.format(sender),
'To: {}'.format(recipient),
'Content-Type: multipart/alternative; boundary="0000000000003c664305827e1862"',
'',
'--0000000000003c664305827e1862',
'Content-Type: text/plain; charset="UTF-8"',
'',
'{}'.format(message),
'',
'--0000000000003c664305827e1862',
])
# sendmail(from, to, msg)
server.sendmail(sender, recipient, msg)
This sends my phone a message that looks like this:
So far so good, but I'm now looking to change the "sender id" that is used to send the message.
In the example above, the sender id is douglas.duhaime.messenger@gmail.com, which is a mouthful. My first question is: Is it possible to programmatically change the sender information using a Google service?
Assuming that's not possible, the next best option would be to register some short domain, configure an MX record for that host address, and then programmatically create users for the MX service at that address.
After attempting to explore this rabbit hole for an hour this morning, I wanted to ask if anyone on StackOverflow could help point me toward some useful entry point to the world of sender id creation, which is quite foreign to me. Any suggestions others can offer would be hugely appreciated.
Update: Hands down the best resource I've found on the subject so far is @JeffAtwood's overview of DIY email.
来源:https://stackoverflow.com/questions/57842922/controlling-the-sender-id-in-sms-packets