@friend
but still I am not able to fix the original error,went through your files and I have not used Jackson
but JSON Array and JSON Object(but that should not be the reason I suppose)
And also,the Json is handled(i.e the list is retrieved from database) before even the mail is sent to the list.
but the error comes when the mail is sent.
Again i would like to highlight, I GET THIS IN FIREFOX (firebug)and NOT IN CHROME BROWSER.(In chrome I get the mail sent successfully message)
Reproducing the error.
Code:
uncaught exception: [Exception... "'You're trying to decode an invalid JSON String: ' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001c (NS_ERROR_XPC_JS_THREW_JS_OBJECT)" location: "JS frame :: chrome://firebug/content/net/spy.js :: callPageHandler :: line 812" data: no]
http://localhost:9191/StaffingApplication/js/ext-all-debug.js
Line 20820 :
disableCache = options.disableCaching !== false ? (options.disableCaching || me.disableCaching) : false; //This line is from ext-all-debug.js
My Controller code:
Code:
@RequestMapping(value = "/email/view.action", method = RequestMethod.POST)
public Object emailView(HttpServletRequest req,HttpServletResponse res) throws AddressException{
/*********************Mail function*********************/
String from="sachitaware21@gmail.com";
String[] toAddress = (req.getParameter("to").split(","));
InternetAddress[] addressTo = new InternetAddress[toAddress.length];
for (int i = 0; i < toAddress.length; i++)
{
addressTo[i] = new javax.mail.internet.InternetAddress(toAddress[i]);
}
String subject = req.getParameter("subject");
String mailBody =req.getParameter("body");
String firstName = (req.getParameter("firstName"));
MailService mailService = new MailService();
mailService.sendMail(from,toAddress,subject,mailBody);
//mailService.sendAlertMail("Exception occurred");
return null;
}
//JSON to iterate over the results and send to the extjs view
@SuppressWarnings("unchecked")
private Map<String,Object> getMap(List<CandidateStatus> candidatestatus){
// Map<String,Object> modelMap = new HashMap<String,Object>(3);
// Map<String,Object> candDetails = new HashMap<String,Object>(7);
Iterator<CandidateStatus> iterator=candidatestatus.iterator();
CandidateStatus astring = new CandidateStatus();
JSONArray jArray = new JSONArray();
while(iterator.hasNext())
{
JSONObject candDetails = new JSONObject();
astring = iterator.next();
candDetails.put("clientName",astring.getRequirement().getClient().getClientName());
candDetails.put("firstName",astring.getCandidate().getFirstName());
candDetails.put("lastName",astring.getCandidate().getLastName());
candDetails.put("email",astring.getCandidate().getEmail());
candDetails.put("phone",astring.getCandidate().getPhone());
candDetails.put("statusTitle",astring.getStatusTitle());
candDetails.put("reqTitle",astring.getRequirement().getReqTitle());
jArray.add(candDetails);
}
//System.out.println("----"+candDetails+"----");
JSONObject modelMap = new JSONObject();
modelMap.put("success",true);
modelMap.put("totalCount",jArray.size());
modelMap.put("data", jArray);
modelMap.toString();
return modelMap;
MailServce class
Code:
@Service("mailService")
public class MailService {
@Autowired
private MailSender mailSender;
@Autowired
private SimpleMailMessage alertMailMessage;
public void sendMail(String from, String[] toAddress, String subject, String mailBody)throws MailException {
/*************Get the username from session***************/
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName(); //get logged in username
System.out.println("----Username is-------"+username+"--------------");
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from);
message.setTo(toAddress);
message.setSubject(subject);
message.setText(mailBody);
Properties props = new Properties();
JavaMailSenderImpl sender = new JavaMailSenderImpl();
props.setProperty("mail.smtp.auth", "true");
props.setProperty("mail.smtp.starttls.enable", "true");
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.debug", "true");
sender.setHost("smtp.gmail.com");
sender.setPort(587);
if(username.equals("options")){
sender.setUsername("sachitaware21");
sender.setPassword("mypasswd");
sender.setJavaMailProperties(props);
}
else if (username.equals("options1")){
sender.setUsername("newastronsolutions");
sender.setPassword("mypasswd");
sender.setJavaMailProperties(props);
}
try {
sender.send(message);
// mailSender.send(message);
}catch(MailException exception)
{
//log the message and go on
System.err.println(exception.getMessage());
}
}
}
I am not using a bean to set the config as I have to change the Email Id based on the current logged in user.
But not able to fix the firebug error I mentioned at the top.
Thanks