RE: liferay 7 email sent costume portlet

thumbnail
Ramalingaiah. D, modified 7 Years ago. Expert Posts: 489 Join Date: 8/16/14 Recent Posts

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

thumbnail
Olaf Kock, modified 7 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
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().

 

 

 

thumbnail
Ramalingaiah. D, modified 7 Years ago. Expert Posts: 489 Join Date: 8/16/14 Recent Posts

Hi Olaf,

Ok,

Thank you for replying.