# Problem trying to send an email using vs code

**URL:** https://forum.codewithmosh.com/t/problem-trying-to-send-an-email-using-vs-code/3557
**Category:** Python
**Created:** [March 25, 2021, 7:33am UTC](https://forum.codewithmosh.com/t/problem-trying-to-send-an-email-using-vs-code/3557 "2021-03-25T07:33:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Micheal](https://avatars.discourse-cdn.com/v4/letter/m/edb3f5/32.png) [@Micheal](https://forum.codewithmosh.com/u/Micheal)
#### Post date: [March 25, 2021, 7:33am UTC](https://forum.codewithmosh.com/t/problem-trying-to-send-an-email-using-vs-code/3557/1 "2021-03-25T07:33:57Z")

</div>

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

> ```
> message = MIMEMultipart()
> message['from'] = "MIcheal francis"
> message['to'] = 'francismicheal259@gmail.com'
> message['subject'] = "This is a test"
> message.attach(MIMEText('Body'))
> 
> ```

> with smtplib.SMTP(host= ‘smtp@gmail.com’, port= 587) as smtp:  
> smtp.ehlo()  
> smtp.starttls()  
> smtp.login(‘toluwalase082@gmail.com’, ‘password’)  
> smtp.send\_message(message)  
> print(‘sent…’)

 ![Screenshot (8)](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/2/21f4515bfd9947ba578662c1d494b5fd75982a88.png)

It’s keep showing me socket.gaierror,  
Please what should I do. Thanks in advance

---

<div class="post-metadata">

### Author: ![SAM](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/sam/32/167_2.png) [@SAM](https://forum.codewithmosh.com/u/SAM)
#### Post date: [March 25, 2021, 5:22pm UTC](https://forum.codewithmosh.com/t/problem-trying-to-send-an-email-using-vs-code/3557/2 "2021-03-25T17:22:27Z")

</div>

Correct the hostname to `smtp.gmail.com`.

---

<div class="post-metadata">

### Author: ![phildude](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@phildude](https://forum.codewithmosh.com/u/phildude)
#### Post date: [May 6, 2022, 12:15pm UTC](https://forum.codewithmosh.com/t/problem-trying-to-send-an-email-using-vs-code/3557/3 "2022-05-06T12:15:09Z")

</div>

My host name is [smtp.gmail.com](http://smtp.gmail.com) already.  
Can’t for the life of me fix it. Thank you.
