Foros de discusión

Send a mail when clicking on a button

Alice ETCHEGARAY, modificado hace 9 años.

Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Hi,

I have a form with different fields and I want to send an email when submitting this form. Is it possible ? And how ?
Thanks you,

Alice
thumbnail
Pankaj Kathiriya, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Master Mensajes: 722 Fecha de incorporación: 5/08/10 Mensajes recientes
There is one web-forms portlet readily available, which provides such functionality.

Refer to wiki link and this.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Thank you, but how to install the app on the portal ?
thumbnail
Pankaj Kathiriya, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Master Mensajes: 722 Fecha de incorporación: 5/08/10 Mensajes recientes
You may download installation file from link, and deploy it on your server by putting it in delpoy folder.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Ok, so I have downloaded the app and create a form like mine, but it seems that the app is limited : there are only 3 types of fields (for example, I want a list, and it's not possible...). This isn't appropriate for me...

Is existing another plugin like Web Form, but more complet ?
thumbnail
Meera Prince, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Sorry Meera, but your links don't correspond with my problem.. I don't want to build a mail form, just send the data of the form by email when clicking on the submit button...
thumbnail
Meera Prince, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
hi
Ok thank you..

It give idea to send mail in liferay. we need to customize or write some logic to send mail according to our requirement.

No portlet or application simply click button and send the mail. if really have it may be specific to their requirement ..
Try above web form portlet there may be some option like that as they said above..


Regards,
Meera Prince.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
I call you again because since this post, I don't manage to send a mail...
Can anyone else help me please ?

Thank you,
Alice
thumbnail
Subhasis Roy, modificado hace 9 años.

RE: Send a mail when clicking on a button

Expert Mensajes: 275 Fecha de incorporación: 20/01/12 Mensajes recientes
Alice ETCHEGARAY:
I call you again because since this post, I don't manage to send a mail...
Can anyone else help me please ?

Thank you,
Alice


Hi Alince,

You can try with Liferay's "MailEngine" API. Check for "com.liferay.util.mail.MailEngine".

 

private static void sendEmail( ){


         InternetAddress[] to = new InternetAddress[] { new InternetAddress(to) };
        InternetAddress from = new InternetAddress(from);
        InternetAddress[] bcc = null;
        if (bcc != null){
            bcc = new InternetAddress[] { new InternetAddress(bcc)
        };
        InternetAddress[] cc = null;
        InternetAddress[] bulkAddress = null;
        boolean htmlFormat = true;
        InternetAddress[] replyTo = null;
        String messageId = null;
        String inReplyTo = null;
        SMTPAccount smtpAccount = null;
        final File[] attachments = null;

        MailEngine.send(from,to, cc, bcc, bulkAddress, subject, body, htmlFormat, replyTo, messageId, inReplyTo, attachments,smtpAccount);

}


Please put your desired values in all the fields before sending.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Ok, but once I have initialized the method, how to call it into the aui:button ?
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
I tried with "<aui:button type="submit" onClick="<%= sendEmail() %>" />" but it doesn't work...
Does anyone have an idea ?
thumbnail
Subhasis Roy, modificado hace 9 años.

RE: Send a mail when clicking on a button

Expert Mensajes: 275 Fecha de incorporación: 20/01/12 Mensajes recientes
You can call an action on this button to fire the send mail.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
Ok, so I have configure the portlet action :

<portlet:actionURL name="sendEmail" var="sendEmailURL"/>
<aui:button type="submit" onClick="<%= sendEmailURL.toString() %>" />


And my method is :

public void sendEmail(){
InternetAddress sender = new InternetAddress();
sender.setAddress("liferay.test@testdomain.com");

InternetAddress receiver = new InternetAddress();
receiver.setAddress("alice_etchegaray@hotmail.com");

String subject = "mail subject";
String body = "body";

MailMessage message = new MailMessage();

message.setFrom(sender);
message.setTo(receiver);
message.setSubject(subject);
message.setBody(body);
message.setHTMLFormat(false);

MailServiceUtil.sendEmail(message);
}


But when I click on the button, nothing is happening !?
thumbnail
Krzysztof Gołębiowski, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Master Mensajes: 549 Fecha de incorporación: 25/06/11 Mensajes recientes
Proper signature for every action method is as follows:

public void actionName(javax.portlet.ActionRequest actionRequest, javax.portlet.ActionResponse actionResponse) throws java.io.IOException, javax.portlet.PortletException

I suppose it cannot find method for your action name, so he calls default processAction which is empty.

Regards,
KG
thumbnail
Subhasis Roy, modificado hace 9 años.

RE: Send a mail when clicking on a button

Expert Mensajes: 275 Fecha de incorporación: 20/01/12 Mensajes recientes
Alice ETCHEGARAY:
Ok, so I have configure the portlet action :

<portlet:actionURL name="sendEmail" var="sendEmailURL"/>
<aui:button type="submit" onClick="<%= sendEmailURL.toString() %>" />


And my method is :

public void sendEmail(){
InternetAddress sender = new InternetAddress();
sender.setAddress("liferay.test@testdomain.com");

InternetAddress receiver = new InternetAddress();
receiver.setAddress("alice_etchegaray@hotmail.com");

String subject = "mail subject";
String body = "body";

MailMessage message = new MailMessage();

message.setFrom(sender);
message.setTo(receiver);
message.setSubject(subject);
message.setBody(body);
message.setHTMLFormat(false);

MailServiceUtil.sendEmail(message);
}


But when I click on the button, nothing is happening !?



In my code snippet I provided a utility method to send mail. You have to write your own action method and call this utility method from there. And action method should have ActionRequest and ActionResponse as param.
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
When I use your method, I have this error and I don't know why :

The method send(InternetAddress, InternetAddress[], InternetAddress[], InternetAddress[], InternetAddress[], String, String, boolean, InternetAddress[], String, String, List<FileAttachment>, SMTPAccount) in the type MailEngine is not applicable for the arguments (InternetAddress, InternetAddress[], InternetAddress[], InternetAddress[], InternetAddress[], String, String, boolean, InternetAddress[], String, String, List<FileAttachment>, SMTPAccount)
Alice ETCHEGARAY, modificado hace 9 años.

RE: Send a mail when clicking on a button

Junior Member Mensajes: 49 Fecha de incorporación: 23/01/14 Mensajes recientes
So, since I have an error with the previous method, I tried with another and I haven't any error. But I don't receive any email...
What is wrong with my code ??

  • My Class Portlet :


public void sendEmail(ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception{
InternetAddress sender = new InternetAddress();
sender.setAddress("liferay.test@testdomain.com");

InternetAddress receiver = new InternetAddress();
receiver.setAddress("my.mail.address@gmail.com");

String subject = "mail subject";
String body = "body";

MailMessage message = new MailMessage();

message.setFrom(sender);
message.setTo(receiver);
message.setSubject(subject);
message.setBody(body);
message.setHTMLFormat(false);

MailServiceUtil.sendEmail(message);
}


  • Edit.jsp :


<portlet:actionURL name="sendEmail" var="sendEmailURL" />
<aui:button type="submit" onClick="<%= sendEmailURL.toString() %>" />


  • Configuration of my portal :


Incoming POP Server = pop.gmail.com
Incoming Port = 995
User Name = my.mail.address@gmail.com
Password = *****

Outgoing SMTP Server = smtp.gmail.com
Outgoing Port = 465
User Name = my.mail.address@gmail.com
Password = *****
Jorge Pineda, modificado hace 9 años.

RE: Send a mail when clicking on a button

New Member Mensajes: 9 Fecha de incorporación: 16/12/14 Mensajes recientes
Hi Alice

did you fix the problem?

It's not working for me!!!

Regards!
thumbnail
David H Nebinger, modificado hace 9 años.

RE: Send a mail when clicking on a button

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Gmail is a bad target to be sending email to. They have filters, etc. in place to block filter and what not.

Usually though the breakdown is not configuring your email connection correctly. You have to use authenticated ssl connection to their specific ports, etc.

You're much better off setting up some local email server for testing or, if you're part of an enterprise, use the enterprise mail system. But gmail will be nothing but trouble.