I sent html as string to email body as message.setContent(body, "text/html");
Body contains this output http://fireforwire.appspot.com/Rankings.html
this contains angular js script. I googled it, and found that I need to include Jquery.js before angular.js to execute in this scenario, even that is not working.
I'm getting output to email as UserId UserName Points {{ country.uservo.userId }} {{ country.uservo.userName }} {{ country.points }}
where my angular is not executed. Plz Plz suggest experts
codebase
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*"%>
<%@ page import="java.net.URLConnection,java.net.URL,org.apache.commons.io.IOUtils"%>
<%
URL url = new URL("http://fireforwire.appspot.com/Rankings.html");
URLConnection con = url.openConnection();
InputStream in = con.getInputStream();
String encoding = con.getContentEncoding(); // ** WRONG: should use "con.getContentType()" instead but it returns something like "text/html; charset=UTF-8" so this value must be parsed to extract the actual encoding
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
System.out.println(body);
%>
<%
out.println("Result: " + body + "\n");
%>
<%
String result;
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
Session session1 = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("sasipudi@gmail.com", "****");
}
});
try {
Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress("sasipudi@gmail.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("sasipudi@gmail.com"));
message.setSubject("Testing Subject");
message.setContent(body, "text/html");
Transport.send(message);
System.out.println("Done");
result="sent succesful";
} catch (MessagingException e) {
throw new RuntimeException(e);
}
%>
<%
out.println("Result: " + result + "\n");
%>
Rankings.html
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<title>AngularJS $http Rest example</title>
<script type="text/javascript">
var app = angular.module("CountryManagement", []);
//Controller Part
app.controller("CountryController", function($scope, $http) {
$scope.countries = [];
$scope.countryForm = {
id : -1,
countryName : "",
population : ""
};
//Now load the data from server
_refreshCountryData();
//HTTP POST/PUT methods for add/edit country
// with the help of id, we are going to find out whether it is put or post operation
$scope.submitCountry = function() {
var method = "";
var url = "";
if ($scope.countryForm.id == -1) {
//Id is absent in form data, it is create new country operation
method = "POST";
url = 'rest/countries';
} else {
//Id is present in form data, it is edit country operation
method = "PUT";
url = 'rest/countries';
}
$http({
method : method,
url : url,
data : angular.toJson($scope.countryForm),
headers : {
'Content-Type' : 'application/json'
}
}).then( _success, _error );
};
//HTTP DELETE- delete country by Id
$scope.deleteCountry = function(country) {
$http({
method : 'DELETE',
url : 'rest/countries/' + country.id
}).then(_success, _error);
};
// In case of edit, populate form fields and assign form.id with country id
$scope.editCountry = function(country) {
$scope.countryForm.countryName = country.countryName;
$scope.countryForm.population = country.population;
$scope.countryForm.id = country.id;
};
/* Private Methods */
//HTTP GET- get all countries collection
function _refreshCountryData() {
$http({
method : 'JSONP',
jsonpCallback: 'callback',
dataType: 'jsonp',
url : 'http://fireforwire.appspot.com/getPoints'
}).then(function successCallback(response) {
//alert(response.data);
$scope.countries=response.data;
console.log(JSON.stringify(response));
//alert(response);
}, function errorCallback(response) {
alert("error"+response);
console.log(response.statusText);
});
}
function _success(response) {
_refreshCountryData();
_clearFormData()
}
function _error(response) {
console.log(response.statusText);
}
//Clear the form
function _clearFormData() {
$scope.countryForm.id = -1;
$scope.countryForm.countryName = "";
$scope.countryForm.population = "";
};
});
</script>
<style>
.blue-button{
background: #25A6E1;
filter: progid: DXImageTransform.Microsoft.gradient( startColorstr='#25A6E1',endColorstr='#188BC0',GradientType=0);
padding:3px 5px;
color:#fff;
font-family:'Helvetica Neue',sans-serif;
font-size:12px;
border-radius:2px;
-moz-border-radius:2px;
-webkit-border-radius:4px;
border:1px solid #1A87B9
}
.red-button{
background: #CD5C5C;
padding:3px 5px;
color:#fff;
font-family:'Helvetica Neue',sans-serif;
font-size:12px;
border-radius:2px;
-moz-border-radius:2px;
-webkit-border-radius:4px;
border:1px solid #CD5C5C
}
table {
font-family: "Helvetica Neue", Helvetica, sans-serif;
width: 50%;
}
caption {
text-align: left;
color: silver;
font-weight: bold;
text-transform: uppercase;
padding: 5px;
}
th {
background: SteelBlue;
color: white;
}
tbody tr:nth-child(even) {
background: WhiteSmoke;
}
tbody tr td:nth-child(2) {
text-align:center;
}
tbody tr td:nth-child(3),
tbody tr td:nth-child(4) {
text-align: center;
font-family: monospace;
}
tfoot {
background: SeaGreen;
color: white;
text-align: right;
}
tfoot tr th:last-child {
font-family: monospace;
}
td,th{
border: 1px solid gray;
width: 25%;
text-align: left;
padding: 5px 10px;
}
</style>
<head>
<body ng-app="CountryManagement" ng-controller="CountryController">
<table>
<tr>
<th>UserId</th>
<th>UserName</th>
<th>Points</th>
</tr>
<tr ng-repeat="country in countries.userpointsList| orderBy:'country.uservo.userId' ">
<td> {{ country.uservo.userId }}</td>
<td >{{ country.uservo.userName }}</td>
<td> {{ country.points }}</td>
</tr>
</table>
</body>
</html>