Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask
- from flask_cors import CORS, cross_origin
- from flask import request,jsonify
- import smtplib, os, cgi
- from email.mime.application import MIMEApplication
- from email.mime.multipart import MIMEMultipart
- from email.mime.base import MIMEBase
- from email.mime.text import MIMEText
- from email import encoders
- app = Flask(__name__)
- CORS(app)
- @app.route('/Send',methods=['POST'])
- def Send():
- fromaddress='rake.son25@gmail.com'
- content = request.json
- toaddress=content['emailTo']
- subject=content['subject']
- text=content['body']
- username = 'rake.son25@gmail.com' # username
- password ='**********************' # password(here I gave my password)
- msg = MIMEMultipart() # this is the message object
- msg['From'] =fromaddress
- msg['To'] = toaddress
- msg['Subject'] =subject
- files =content['file']
- msg.attach(MIMEText(text)) # Attaching subject tect to body, you can provide you own custom
- try:
- for f in files or []:
- path = os.path.join(os.getcwd(), f)
- if os.path.isfile(path):
- part = MIMEBase('application', "octet-stream")
- part.set_payload(open(path, "rb").read())
- encoders.encode_base64(part)
- part.add_header('Content-Disposition', 'attachment; filename=' + os.path.basename(path))
- msg.attach(part)
- server = smtplib.SMTP('smtp.googlemail.com')
- server.ehlo()
- server.starttls()
- server.login(username,password)
- server.sendmail(fromaddress,toaddress,msg.as_string())
- server.quit()
- return("Mail send successfully")
- except IOError:
- return("Error sending mail")
- if __name__=="__main__":
- app.run(debug=True)
- <div class="input-group">
- <input type="file" value="Browse" id="fl" /><button ng-click="addFile()">Add Files</button>
- <span ng-repeat="f in fileName"><a>{{f}} </a> <a href="" ng-click="removeFile(f)">Remove</a></span>
- </div>
- myApp.controller('formController',['$scope','$http', function($scope,$http) {
- //$('.datepicker').datepicker();
- $scope.fileName=[];
- debugger;
- //$scope.formData = {};
- // $scope.data = {};
- $scope.save=function(){
- console.log($scope.formData)
- debugger
- $scope.formData.to = "rakeshlochansarma25@gmail.com";
- $scope.formData.from = "rake.son25@gmail.com";
- $scope.formData.subject="test";
- $scope.formData.body="test me"
- var body="Email :"+$scope.formData.email+', Phone No.'+$scope.formData.phno+';'
- $http({
- method:'POST',
- url:'http://127.0.0.1:5000/Send',
- headers: {
- 'Content-Type': 'application/json;charset=utf-8'
- },
- data:{emailTo:'rakeshlochansarma25@gmail.com',subject:'Candidate Profile :'+$scope.formData.fullName,body:body,file:$scope.fileNameString}
- })
- .then(function(resp){
- console.log(resp);
- },function(error){
- console.log(error);
- });
- };
- $scope.addFile = function(){
- debugger
- var flname=[]
- flname = document.getElementById("fl").files;
- for (var i = 0; i < flname.length; i++){$scope.fileName.push(flname[i].name);}
- $scope.fileNameString = $scope.fileName.join();
- // alert(JSON.stringify($scope.fileName));
- };
- $scope.removeFile = function(fl) {
- $scope.fileName.splice($scope.fileName.indexOf(fl),1);
- };
- $scope.confirm = function(){
- debugger
- $scope.modalInstance.close({ delete : true});
- };
- $scope.cancel = function(){
- $scope.modalInstance.dismiss('cancel');
- };
- }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement