Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python, sending E-mails
#1
So im trying to make a fun little application thingy, wich sends an email (with my gmail to my gmail for testing) (using python 3.7.0) and i tried putting like info in it but it displays an error, how do i make sure the message can be sent? btw i just replaced my mail with my mail and password by password haha. note i only showed a part of the code here
code:
import smtplib
 
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("my-emaim", "password")
 
msg = "Hello, my name is", name, lastname, ", I am a", age, "year old", gender, ". I live in", country, adress, ". Thank you for reading my E-mail."
server.sendmail("mymail", "mymail", msg)
server.quit()
error:
Error:
Traceback (most recent call last): File "C:\Users\Balder\Documents\Applicant.py", line 28, in <module> server.sendmail("[email protected]", "[email protected]", msg) File "C:\Users\Balder\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 882, in sendmail (code, resp) = self.data(msg) File "C:\Users\Balder\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 564, in data q = _quote_periods(msg) File "C:\Users\Balder\AppData\Local\Programs\Python\Python37-32\lib\smtplib.py", line 176, in _quote_periods return re.sub(br'(?m)^\.', b'..', bindata) File "C:\Users\Balder\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 192, in sub return _compile(pattern, flags).sub(repl, string, count) TypeError: expected string or bytes-like object
Reply
#2
replace
msg = "Hello, my name is", name, lastname, ", I am a", age, "year old", gender, ". I live in", country, adress, ". Thank you for reading my E-mail."
with
msg = f"Hello, my name is {name} {lastname}. I am a {age} year old {gender}. I live in {country} {adress}. Thank you for reading my E-mail."
At the moment msg is a tuple. Also learn to use str.format() method or f-strings.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sending a text from Python sawtooth500 2 159 Apr-14-2024, 01:56 PM
Last Post: sawtooth500
  Sending string commands from Python to a bluetooth device Rovelin 13 9,439 Aug-31-2021, 06:40 PM
Last Post: deanhystad
  Sending Out Email via Python JoeDainton123 1 4,762 Aug-31-2020, 12:54 AM
Last Post: nilamo
  Python sockets : Client sending to the server nico31780 0 2,333 May-17-2020, 07:56 PM
Last Post: nico31780
  problems sending BIN file with XMODEM python shaya2103 0 2,823 Nov-23-2019, 10:27 AM
Last Post: shaya2103
  Mail sending Python - What it's wrong? airwawekz 1 2,692 Jan-30-2019, 03:20 PM
Last Post: gontajones
  Problem in sending email using python nhoh007 1 2,523 Aug-25-2018, 07:20 PM
Last Post: typic
  Sending E-mails keegan_010 3 4,164 Aug-21-2018, 08:06 AM
Last Post: keegan_010
  Sending different color codes in python at certain times Kimzer 4 3,413 Jun-18-2018, 06:56 PM
Last Post: gontajones
  sending data to second python script Cyberfly 1 3,152 Jan-29-2018, 10:09 AM
Last Post: Cyberfly

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020