# Error with sending email massage

**URL:** https://forum.codewithmosh.com/t/error-with-sending-email-massage/14186
**Category:** Python
**Created:** [August 7, 2022, 5:44am UTC](https://forum.codewithmosh.com/t/error-with-sending-email-massage/14186 "2022-08-07T05:44:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ighedome](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/ighedome/32/3970_2.png) [@ighedome](https://forum.codewithmosh.com/u/ighedome)
#### Post date: [August 7, 2022, 5:44am UTC](https://forum.codewithmosh.com/t/error-with-sending-email-massage/14186/1 "2022-08-07T05:44:58Z")

</div>

Hi Everyone,

Please I need help with email sending. I have followed the codes as Mosh explained in the course video but it is not working. It raised ‘typeerror’ on line 7, that object does not support item assignment. Please see what corrections are required in this script.

 ![emailError](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/e/e36a81bed9109ed6a9e726168bc476cfed82227a.jpeg)

Please I need help as quickly as possible. I have been stuck here for days now and cannot progress for now

---

<div class="post-metadata">

### Author: ![MHarten](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/mharten/32/4199_2.png) [@MHarten](https://forum.codewithmosh.com/u/MHarten)
#### Post date: [August 7, 2022, 8:21am UTC](https://forum.codewithmosh.com/t/error-with-sending-email-massage/14186/2 "2022-08-07T08:21:57Z")

</div>

At a glance, you seem to be missing () after MIMEMultipart on line 6, if you can put your code directly into a reply for me to look at I can check it a bit more thoroughly. You can do this by copy-pasting it into the comment with ``` above and below the code. The ` key is to the left of the 1 key.

For example, here is how my notes look from that section:

```auto
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from pathlib import Path
import smtplib

message = MIMEMultipart()
message["from"] = "Test User"
message["to"] = "notarealemail@gmail.com"
message["subject"] = "This is a test"
message.attach(MIMEText("Body"))
message.attach(MIMEImage(Path("mosh.png").read_bytes))

with smtplib.SMTP(host="smtp.gmail.com", port=587) as smtp:
    smtp.ehlo()
    smtp.starttls()
    smtp.login("notarealemail@gmail.com", "thisiswhereapasswordgoes")
    smtp.sendmessage(message)
    print("Sent...")

```

Lastly, you are going to want to edit this post to remove your login credentials, and likely change your password for good measure if you have it tied to any other logins that are important to you. Just in case.

---

<div class="post-metadata">

### Author: ![ighedome](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/ighedome/32/3970_2.png) [@ighedome](https://forum.codewithmosh.com/u/ighedome)
#### Post date: [August 7, 2022, 10:55pm UTC](https://forum.codewithmosh.com/t/error-with-sending-email-massage/14186/4 "2022-08-07T22:55:06Z")

</div>

Thanks @MHarten for your response. I have implemented your first observation, the missing () after MIMEMultipart, the error now is “smtplib.SMTPConnectError:” from line 12.  
Meanwhile the email and password in this post are not the real ones.

Below is the editable version of my code:

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

message = MIMEMultipart()  
message[“from”] = “Mose Someone”  
message[“to”] = “[someone@gmail.com](mailto:someone@gmail.com)”  
message[“subject”] = “This is test mail”  
message.attach(MIMEText(“Body of Message”))

with smtplib.SMTP(host=“[smtp.gmail.com](http://smtp.gmail.com)”, port=587) as smtp:  
smtp.ehlo()  
smtp.starttls()  
smtp.login(“[someone@gmail.com](mailto:someone@gmail.com)”, “newpasskey+90”)  
smtp.send\_message(message)  
print(“sent…”)

The code still cannot run. Below is the new error message:

Traceback (most recent call last):  
File “c:/…/Helloworld/e\_mailling.py”,  
line 12, in   
with smtplib.SMTP(host=“[smtp.gmail.com](http://smtp.gmail.com)”, port=587) as smtp: File “C:.…\Python38-32\lib\smtplib.py”, line 256, in **init**  
raise SMTPConnectError(code, msg)  
smtplib.SMTPConnectError: (421, b’Service not available’)
