0

As you can see below i have a script that uses smtp module to send mail back to the usr_mail , the function mail_man takes an argument message and sends via mail , through out my testing i passed some simple messages to the script but i does not seem to send the messages passed instead it shows this message has no body text

some messages examples :

"hello world !!! :) "

"you got mail from : " + str(usr_mail)

" @ somthing "

how can i send a paragraph like message with symbols numbers letters using smtp module

import smtp


def mail_man(message):

    handle = smtplib.SMTP('smtp.gmail.com', 587)
    handle.starttls()
    handle.login(usr_mail , pass_wrd)
    handle.sendmail(usr_mail , usr_mail , message)
    handle.quit()


    print ( " Successfully sent email to :: " +  usr_mail)
    return 



if __name__ == "__main__":
    print (usr_mail , pass_wrd )
    mail_man(message="hello world !!! :) ")
Sec Team
  • 47
  • 8
  • The duplicate is perhaps too techoical; the short and sweet explanation is that in none of your attempts does `message` look even remotely like a valid SMTP message. – tripleee Jul 21 '20 at 20:17

1 Answers1

1

I would recommend creating a separate file for paragraph responses and then importing the EmailMessage() class from smtplib which will allow you to pass that message to the email. I would recommend trying this:

import smtplib
from email.message import EmailMessage

# Open the plain text file.
txtfile = 'name_of_your_file'
with open(txtfile) as f_obj:
   # Create a blank message and then add the contents of the
   # file to it
   msg = EmailMessage()
   msg.set_content(f_obj.read())

msg['Subject'] = 'your_subject'
msg['From'] = me
msg['To'] = you

# Send the message through your own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()

This will allow you to send any types of long messages because it saves the contents of the file as a string and then adds it to the file so there are no conversion errors.

Maxim
  • 276
  • 2
  • 6