Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: liferay 7 email sent costume portlet
Hi
package com.email.sending.portlet;
import com.email.sending.constants.MailSendPortletKeys;
import
com.liferay.mail.kernel.model.MailMessage;
import
com.liferay.mail.kernel.service.MailServiceUtil;
import
com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import
com.liferay.portal.kernel.servlet.SessionMessages;
import com.liferay.portal.kernel.util.ParamUtil;
import java.io.IOException;
import javax.portlet.ActionRequest;
import
javax.portlet.ActionResponse;
import java.net.InterfaceAddress;
import javax.portlet.Portlet;
import javax.portlet.PortletException;
import org.osgi.service.component.annotations.Component;
import com.liferay.mail.kernel.model.MailMessage;
import
com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.util.ParamUtil;
import java.io.IOException;
import java.net.InterfaceAddress;
import javax.mail.internet.AddressException;
import
javax.mail.internet.InternetAddress;
import
javax.mail.internet.InternetHeaders;
import
javax.portlet.ActionRequest;
import
javax.portlet.ActionResponse;
import
javax.portlet.Portlet;
import javax.portlet.PortletException;
import java.io.IOException;
import java.net.InterfaceAddress;
import javax.mail.internet.InternetAddress;
import org.osgi.service.component.annotations.Component;
/**
* @author EBS
*/
@Component(immediate = true,
property = {
"com.liferay.portlet.display-category=category.sample",
"com.liferay.portlet.instanceable=true",
"javax.portlet.display-name=EmailSending Portlet",
"javax.portlet.init-param.template-path=/",
"javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.name=" + MailSendPortletKeys.MailSend,
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user" },
service = Portlet.class)
public class MailSendPortlet extends
MVCPortlet {
public void MailSendPortlet(ActionRequest actionRequest,
ActionResponse actionResponse)
throws IOException,
PortletException {
System.out.println("====sendMailMessage===");
String from = ParamUtil.getString(actionRequest,
"from");
String to =
ParamUtil.getString(actionRequest, "to");
// String InternetAddress =
// ParamUtil.getString(actionRequest,"InternetAddress");
// String
//
senderMailAddress=ParamUtil.getString(actionRequest,"ramu402dd");
// String
//
receiverMailAddress=ParamUtil.getString(actionRequest,"dramu402");
System.out.println("1111" + to);
try {
InternetAddress fromAddress = new
InternetAddress(from);
InternetHeaders fro = new
InternetHeaders(from);
InternetAddress toAddress = new InternetAddress(to);
MailMessage mailMessage = new MailMessage();
mailMessage.getFrom(fromAddress);
mailMessage.getTo(toAddress);
MailServiceUtil.sendEmail(mailMessage);
// mailMessage.setFrom(new InternetAddress("ramu402dd"));
// mailMessage.setTo(new InternetAddress("dramu402"));
//SessionMessages.add(actionRequest.getPortletSession(),
"mail-send-success");
} catch
(AddressException e) {
e.printStackTrace();
}
}
}
error The method getTo() in the type MailMessage is not applicable for the arguments (InternetAddress)
please help me
Thank you
Ramalingaiah. D:InternetAddress fromAddress = new InternetAddress(from); InternetHeaders fro = new InternetHeaders(from); InternetAddress toAddress = new InternetAddress(to); MailMessage mailMessage = new MailMessage(); mailMessage.getFrom(fromAddress); mailMessage.getTo(toAddress);
error The method getTo() in the type MailMessage is not applicable for the arguments (InternetAddress)
The error message tells you exactly what the matter is: The method getTo
results in an InternetAddress, but takes no parameter. You most
likely want to call setTo()
. Alternatively store the
result somewhere. But as you call it on a new object, there wouldn't
be anything to store. Just use setTo()
.
Hi Olaf,
Ok,
Thank you for replying.
Powered by Liferay™