Search code examples
pythonsmssmtplib

Sending Verizon SMS message via Python and smtplib


I can make smtplib send to other email addresses, but for some reason it is not delivering to my phone.

import smtplib
msg = 'test'
server = smtplib.SMTP('smtp.gmail.com',587)  
server.starttls()  
server.login("<username>","<password>")  
server.sendmail(username, "<number>@vtext.com", msg)  
server.quit()

The message sends successfully when the address is a gmail account, and sending a message to the phone using the native gmail interface works perfectly. What is different with SMS message numbers?

Note: using set_debuglevel() I can tell that smtplib believes the message to be successful, so I am fairly confident the discrepancy has something to do with the behavior of vtext numbers.


Solution

  • The email is being rejected because it doesn't look an email (there aren't any To From or Subject fields)

    This works:

    import smtplib
    
    username = "account@gmail.com"
    password = "password"
    
    vtext = "1112223333@vtext.com"
    message = "this is the message to be sent"
    
    msg = """From: %s
    To: %s
    Subject: text-message
    %s""" % (username, vtext, message)
    
    server = smtplib.SMTP('smtp.gmail.com',587)
    server.starttls()
    server.login(username,password)
    server.sendmail(username, vtext, msg)
    server.quit()