Python Can't Send Emails to Gmail

python-can for python3
python-can github
python-can receive message
python-can bus tutorial
python-can vector example
python-can tools
python-can documentation pdf
python-can bus status

I have a python script to send emails. I utilize this to send alerts to my email and phone. But for some reason the emails are not received when sending to a gmail account. The big difference that I see between my code and other examples is I cannot use the smtp.gmail.com. Here's my email/text function:

import smtplib

sender = 'xxxx@company.com'
smtpObj = smtplib.SMTP('smtp.company.com')

def text_func ( subject,text_message ):
    text_receivers = ['##########@vtext.com',
        'xxxxxxxx@company.com',
        'xxxxxxxx@gmail.com'
    ]
    text_message = """Subject: %s

    %s
    """ % (subject, text_message)

    smtpObj.sendmail(sender, text_receivers, text_message)

The above code works for sending an sms to my phone and my work email but not to gmail. I checked and made sure the email doesn't show up in a spam folder. Google seems to be blocking it completely. Any ideas?

This may not be correct, as I don't have much experience with the texting side of smtplib, but it looks like you need to start the TLS connection. I would change your script to the following:

import smtplib

sender = 'xxxx@company.com'
smtpObj = smtplib.SMTP('smtp.company.com')
smtpObj.starttls()

def text_func ( subject,text_message ):
text_receivers = ['##########@vtext.com',
    'xxxxxxxx@company.com',
    'xxxxxxxx@gmail.com'
]
text_message = """Subject: %s

%s
""" % (subject, text_message)

smtpObj.sendmail(sender, text_receivers, text_message)

python-can · PyPI, The can package provides controller area network support for Python developers - hardbyte/python-can. Develop and Deploy Apps with Python On Azure and Go Further with AI And Data Science.

Found the solution.

import smtplib
from email.mime.text import MIMEText

sender = 'xxxx@company.com'
smtpObj = smtplib.SMTP('smtp.company.com')

def text_func ( subject,text_message ):
    text_receivers = ['##########@vtext.com',
        'xxxxxxxx@company.com',
        'xxxxxxxx@gmail.com'
    ]

    cont = '''\
       <html>
         <head></head>
         <body>
           <p>{0}</p>
         </body>
       </html>
       '''.format(text_message)

    msgTo = ""
    for person in text_receivers:
        msgTo += "{0} ".format(person)

    msg = MIMEText(cont, 'html')

    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = msgTo

    smtpObj.sendmail(sender, text_receivers, msg.as_string())

hardbyte/python-can: The can package provides controller , The python-can library provides Controller Area Network support for Python, providing common abstractions to different hardware devices, and  Looking for learn python programming? Search now! eTour.com is the newest place to search, delivering top results from across the web.

You may need to change your gmail settings to allow less secure apps into your account. See link below from Nick, an accounts expert at google.

https://support.google.com/accounts/answer/6010255?hl=en

Option 2: Change your settings to allow less secure apps into your account. We don't recommend this option because it can make it easier for someone to break into your account. If you want to allow access anyway, follow these steps: Go to the Less secure apps section of your Google Account. Turn on Allow less secure apps. If you don't see this setting, your administrator might have turned off less secure app account access.

[PDF] python-can, Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can  Looking for learn python programming? Get your questions answered. Discover learn python programming and related content.

Step 1:

Allowing less secure apps to access your account

For Sending the Email:

import smtplib

gmail_user = 'you@gmail.com'  
gmail_password = 'P@ssword!'

sent_from = gmail_user  
to = ['me@gmail.com', 'bill@gmail.com']  
subject = 'OMG Super Important Message'  
body = 'Hey, what's up?\n\n- You'

email_text = """\  
From: %s  
To: %s  
Subject: %s

%s
""" % (sent_from, ", ".join(to), subject, body)

try:  
    server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
    server.ehlo()
    server.login(gmail_user, gmail_password)
    server.sendmail(sent_from, to, email_text)
    server.close()

    print 'Email sent!'
except:  
    print 'Something went wrong...'

Introduction to Python, Connection are made via DB9 or 3-way screw terminal. There is an easy-to-​install SocketCAN driver, and programming can be accomplished in C or Python. From importing data to machine learning. All first chapters are free. On demand.

I also faced the same problem. When I checked my inbox from webmail, I found that the email was rejected by gmail. The problem was solved by adding the "From" header to the email.

import smtplib, ssl
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

sender_email = "test@example.com"
receiver_email = "example@gmail.com"
password = "pass1234"
host = "example.com"
port = 465
message = MIMEMultipart("alternative")
message["Subject"] = "Email Subject"
message["From"] = sender_email
message["To"] = receiver_email
text = "This is the email Body"
message.attach(MIMEText(text, "plain"))
context = ssl.create_default_context()
with smtplib.SMTP_SSL(host, port, context=context) as server:
    server.login(sender_email, password)
    server.sendmail(
        sender_email, receiver_email, message.as_string()
    )

PiCAN2, python example.py can0 import socket import struct import sys # CAN frame packing/unpacking (see `struct can_frame` in <linux/can.h>)  python-can¶. The python-can library provides Controller Area Network support for Python, providing common abstractions to different hardware devices, and a suite of utilities for sending and receiving messages on a CAN bus.

Python Can, In this article, we offer several different projects, resources, and tutorials that you can use to start building things with Python. The can package provides controller area network support for Python developers; providing common abstractions to different hardware devices, and a suite of utilities for sending and receiving messages on a can bus. The library supports Python 2.7, Python 3.5+ as well as PyPy 2 & 3 and runs on Mac, Linux and Windows. Library Version.

What Can I Do With Python? – Real Python, I have a CAN bus (PCAN) with several inputs. I try to read the inputs in python and print them on the console. The first message I get from the bus  To install python-can using the Kvaser CANLib SDK as the backend: Install the latest stable release of Python. Install Kvaser’s latest Windows CANLib drivers. Test that Kvaser’s own tools work to ensure the driver is properly installed and that the hardware is working. Download and install the latest driver for your interface from PEAK

Receive message on CANbus always returns same value with , You could use a global variable containing a dictionary instead of the default value; it's a matter of taste. How can I pass optional or keyword parameters from one  python-can. The Controller Area Network is a bus standard designed to allow microcontrollers and devices to communicate with each other. It has priority based bus arbitration and reliable deterministic communication. It is used in cars, trucks, boats, wheelchairs and more.

Comments
  • When I add that line it throws and error. I'm trying to troubleshoot this now. raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server.
  • @Rachel I have had issues with that in the past, just keep trying different things.
  • Good thought but this did not fix it.
  • I don't want to send FROM a gmail account, only TO a gmail account. And I cannot use smtp.gmail.com, it's coming from my companies internal smtp gateway.