Monday 11 March 2019

How to send the output of python code in attachment in mail by Raj Gupta


In AWS EC2 server..install AWS CLI and run the python code.

update the ec2
[ec2-user@ip-172-31-81-19 ~]$ sudo yum update

install the aws cli
[ec2-user@ip-172-31-81-19 ~]$ sudo pip install --upgrade awscli


now configure the aws cli
[ec2-user@ip-172-31-81-19 ~]$ aws configure


now write and save the python code
[ec2-user@ip-172-31-81-19 ~]$ vi raj2.py ( for saving use esc after that :x then enter)          


now run the python code by using below command   
[ec2-user@ip-172-31-81-19 ~]$ python raj2.py


now install the below xlwt
[ec2-user@ip-172-31-81-19 ~]$ sudo python -m pip install xlwt

also install mailx [ec2-user@ip-172-31-81-19 ~]$ sudo yum install mailx -y

now for sending mail use the below command [ec2-user@ip-172-31-81-19 ~]$ echo 'These are contents of my mail' | mailx -s 'This is my email subject' -a /home/ec2-user/cost_optimization.xls rajkumargupta14 @gmail.com                                                                                      

No comments:

Post a Comment