Send email from python programming with SMTP

Send email from python: in this tutorial, we are going to learn about the step by step process to send email using python programming even we are going to write a program.

in terms of sending emails, python has really ice modules that we can use to send an email. so today we are going to use email and smtplib modules to send emails using python.


 Send email from python programming with SMTP

What we are going to learn.

  • The basics of emailing.
  • Send email to multiple addresses
  • Send email using CC and BCC.

Send email from python programming with SMTP

Basic of Email- Send Emails with the smtplib module.

Program to send email using smtplib

    
    import smtplib

    def send_email(host, subject, to_addr, from_addr, body_text):

    """
    Send an email
    """
    BODY = "\r\n".join((
                   "From: %s" % from_addr,
                   "To: %s" % to_addr,
                   "Subject: %s" % subject ,
                   "", body_text ))
    server = smtplib.SMTP(host)
    server.sendmail(from_addr, [to_addr], BODY)
    server.quit()

    if __name__ == "__main__":

    host = "mySMTP.server.com"
    subject = "Test email from Python"
    to_addr = "mike@someAddress.org"
    from_addr = "python@mydomain.com"
    body_text = "Here is my first email!"
    send_email(host, subject, to_addr, from_addr, body_text)


Note: you note that this code doesn't require any username or password in it. so if your server requires authentication then you need to add the following code right after you create the server object.



    server.login(username, password)



simply we first import the smtplib module and then create a separate function. and then we create a BODY string in which we include the necessary information. and then we create an object from the host server and then use the built-in function sendmail to send the mail. and then quite the connection to the server.


Send Email to Multiple Address

Program to send email using multiple addresses


   import smtplib


   def send_email(subject, body_text, emails):

   """
   Send an email
   """
   host = some.server.com
   from_addr = example@mydomain.com

   BODY = "\r\n".join((

                   "From: %s" % from_addr,
                   "To: %s" % ', '.join(emails),
                   "Subject: %s" % subject ,
                   ""body_text ))
   server = smtplib.SMTP(host)
   server.sendmail(from_addr, emails, BODY)
   server.quit()

   if __name__ == "__main__":

   emails = ["mike@someAddress.org", "someone@gmail.com"]
   subject = "Test email from Python"
   body_text = "here is my first email!"
   send_email(subject, body_text, emails)


Here we remove the add parameter and added a list of email addresses. and to make this work we create a comma-separated string in the portion of the BODY and pass the list of emails to the sendmail method.

Send Emails using CC and BCC.

Program to send emails with CC and BCC sections.


   import smtplib

   def send_email(subject, body_text, to_emails, cc_emails, bcc_emails):
   """
   Send an email
   """

   host = some.server.com
   from_addr = example@mydomain.com

   BODY = "\r\n".join((
                   "From: %s" % from_addr,
                   "To: %s" % ', '.join(to_emails),
                   "CC: %s" % ', '.join(cc_emails),
                   "BCC: %s" % ', '.join(bcc_emails),
                   "Subject: %s" % subject ,
                   ""body_text ))

   emails = to_emails + cc_emails + bcc_emails

   server = smtplib.SMTP(host)
   server.sendmail(from_addr, emails, BODY)
   server.quit()

   if __name__ == "__main__":
   emails = ["mike@somewhere.org"]
   cc_emails = ["someone@gmail.com"]
   bcc_emails = ["schmuck@newtel.net"]

   subject = "Test email from Python"
   body_text = "this is my first email !"
   send_email(subject, body_text, emails, cc_emails, bcc_emails)


In the above code, we create CC and BCC fields and then combine the 3 lists into one so we can pass the combined list to the sendmail() method. 

Note: some email clients may allow the recipient to see the BCC list via the email headers. 
So I think now you should understand that how to send the email using python programming and SMTP module and if you like this post then please share it with your friends and don't forget to follow us. 

Model of computer system - Introduction and components

Model of Computer: In this tutorial, we are going to learn about the simple model of computer systems and see the main components of the computer system.

Simple model of computer system


Simple Model of computer system

Mainly there are four things which can organize a computer.


  1. Input
  2. Memory
  3. Processing Unit
  4. Output

model of computer


What is Input?

Input is a set of instructions that can be given to the computer to process the data.

for example, our body needs the energy to work. and to provide energy to our body we eat regular food. so in our terms, food is work as an input.
likewise, the computer needs input to work. and it can be given by mouse, keyboard, etc...


What is Memory?

Memory is a physical space where the compute saves the data to process later. using memory we also can save the data for later and modify that data when we need it. we also can delete the data.

for example, when we eat food it comes to our stomach and stored and this stored food gives us the regular energy to work.


What is the Processing Unit?

The processing unit is the brain of computer system. it solves a particular problem like it preforms operations on a given problem using our instructions.

for example, if we run, walk or talk all are managed by our brain. without the brain, we are not able to work at a single time.
likewise, the processing unit is the brain of the computer and without processing, the unit computer cannot work even a single second. 
like if we click on any point using the mouse then it gives the signal to the PU and processing unit react as situation.


What is Output?

The output is the thing that comes when the computer process any information. like in the calculator if we add two numbers like 2 + 2. then result comes 4. this is the output.

for example, if we thought that you want to eat a thing then the signal goes to brain and brain work using the process. like first you pick up the thing and then eat it and this is the output.

Note: if a process does not produce any output then this process is not real.

So, these are four major components which are very important for the working of a computer system.

Why we need a computer Machine?

A computer machine designed to carry out algorithms for processing data and instructions. an input unit is provided to read the algorithm and the data to be processed by the algorithm. the memory unit stores the algorithm and computed value the processing unit interprets the instructions and carries them out. it has the capability to perform arithmetic operations, character manipulation operations and logical operations. the output unit prints or display computed results.




If you like this information then please share this post as much as possible and don't forget to comment me your queries and suggestions. 

What is an Algorithm explanation with example

algorithm:  if you are searching for an answer to the question that what is an algorithm and why and where we use the algorithmthen you are in right place. because in this post, we are going to learn about the term called an algorithm. and how important it is to solve a particular problem, not a technical problem but also a non-technical problem. 


What is an Algorithm explanation with example
what is algorithm

What is an Algorithm in Programming?


In programming, an algorithm is a step by step method to solving a problem. and in another word, we can say that an algorithm has a finite sequence of instructions. 

and in order to solve a particular problem, we need a precise and step by step method. not in the term of technology but in our daily life we need a step by step plan to do any work. 


One-click for us:



And to obtain an algorithm we need three things.

  1. Input
  2. a sequence of instructions to process the input.
  3. Result
What is an Algorithm explanation with example
steps of algorithm

For example, to make a recipe for making potato bondas we need a step by step process like we first need the list of ingredients and then making method and then the expected result will come. 

Ingredients

Potatoes 250 grams, chopped onions, finely chopped green chilies, gram flour, oil for frying, water for the batter, salt, etc...

Method

Step 1: Boil potatoes till cooked peel and mash them until they are soft. 
Step 2: Mix fried onions, green chilies and salt with the mashed potatoes. 
Step 3: Take little portions of the mixture and make small balls.
Step 4: Mix gram flour, water, and a little salt and beat well till a smooth and creamy batter is obtained. 
Step 5: Dip the potato balls in the batter. take out and deep fry in oil on a low fire.
Step 6: Take out when the balls are fried to a golden brown color. 

Result

Potato bonds are ready.

In the above example, the Ingredients are work as an input. and the method is working as a sequence of instructions. and then the result comes out as our potato bonds are ready. 



An algorithm has the following five basic characteristics.


First: an algorithm begins with instructions to accept inputs. these inputs are processed by the subsequence and sequence of instructions in the algorithm. 

Second: The sequence of instructions specified in the algorithms must be precise and unambiguous. and not be vague. 
Third: Each instruction must be sufficiently basic such that it can be carried out by a person with paper and pencil. 
Fourth: The total time consumed by the algorithm must be finite. 
Five: An algorithm must produce one or more outputs. 

let's take another technical example.

A step by step procedure to find the average number of vowels in a passage.

Step 1: Let the number of characters = 0

Step 2: Let the number of vowels = 0
Step 3: Repeat Steps 4, 5, 6 and 7 until no more characters are left in the passage. 
Step 4: Read one character from the passage.
Step 5: Add 1 to a number of characters.
Step 6: If the character is any one of the letters A, E, I, O, U, a, e, I, o, u, add 1 to the number of vowels.
Step 7: Move to the next character. 
Step 8: Average Number of vowels = Number of vowels / Number of characters
Step 9: Write the average number of vowels, number of characters.
Step 10: Stop.

A process only qualifies as an algorithm. if

  • It has Input
  • The sequence of instructions is precise.
  • The total number of instructions is finite.
  • The process needs to be terminated in any condition.
  • There needs to be output. 

and in the above process to find the average number of vowels in a passage is an algorithm because it has the number of inputs and the finite number of sequence and instructions and terminate on a condition and have a sufficient output. 

Note: So I think now you understand that what is an algorithm and why and where we use it. 



Other Post

send email using python
IF you like knowledge then please share this post as much as possible and don't forget to comment me your suggestions. 

Download C Plus Plus programming pdf book for free

Download C Plus Plus programming pdf book for free: This pdf file containing the knowledge of advance c plus-plus programming pdf book for free and this book is also referred to another website called goalkicker.com. so feel free to download this advance c plus-plus programming book notes.

download c plus plus programming pdf book for free, programming books

download c plus plus programming book for free, learn basic programming

Also, refer to our other posts.


Also, refer to our video and subscribe to the channel for learning programming.


Please if you like this post then please click on any ad for helping us and also comment us your questions and share this post with your friends and on all your social media handles.

Download Angular JS pdf book for free

Download Angular JS pdf book for free: This pdf file containing the knowledge about Angular JS Notes. this pdf refers to another website called goalkicker.com. am only using this pdf for my viewers. so feel free to download this advance angular js framework pdf book notes.


download angular js pdf book for free, angular js book
                                                     

Also, download other programming books


Also View

Method to download Udemy, Udacity, Coursera and other educational courses for free.


                          

Download the Bus reservation system project files.
                                                  


Other Projects
Please, guys if you like this post then please share this post with your friends and on all your social media handles. also, do comment in the comment section for any question and queries related to this post.

Download Android programming pdf book for free

Download Android programming pdf book for free: This pdf file containing the knowledge about Android Programming Notes. this pdf file refers to the other website called goalkicker.com. I only include this book for my viewers. so feel free to download this Android programming pdf book.

Note: This link contains the sort URL. so be patient when you will download the book.               


Also, download other programming books


Also View

Method to download Udemy, Udacity, Coursera and other educational courses for free.



Download the Bus reservation system project files.

                     
Other Projects:


Please, guys if you like this post then please share this post with your friends and on all your social media handles. also, do comment in the comment section for any question and queries related to this post.

Download c programming pdf book for free

Download c programming pdf book for free: This pdf file containing the knowledge about C programming. this pdf file refers to the other website called goalkicker.com. so feel free to download this C programming book notes.

download c programming book pdf for free, c programming


Note: This link contains the sort URL. so be patient when you will download the book.

                      

Also, download other programming books

Also View

A Bus Reservation system project in java.


Download the project files.

                      

Other Projects:

Please, guys if you like this post then please share this post with your friends and on all your social media handles. also, do comment in the comment section for any question and queries related to this post.