I did this configuration
email.server.enabled=true
email.server.port=25
email.server.domain=alfresco.com
email.inbound.unknownUser=anonymous
email.server.allowed.senders=.*
In Class
Properties mailServerProperties = new Properties();
mailServerProperties = System.getProperties();
mailServerProperties.put("mail.smtp.host", "localhost");
mailServerProperties.put("mail.smtp.port", "25");
Session session = Session.getDefaultInstance(mailServerProperties, null);
session.setDebug(false);
Message message = new MimeMessage(session);
String fromAddress = "admin@alfresco.com";
message.setFrom(new InternetAddress(fromAddress));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("dharmrajgurjar1990@gmail.com"));
message.setSubject(subject);
// Create the message part with body text
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(body);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Create the Attachment part
//
// Get the document content bytes
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
Transport.send(message);
Can you clarify whether you want to send emails without attachments or with attachments ?
There is an action OOTB which allows to send emails to a user or a group but attachment feature is not available as of now.
This action class extends ActionExecuterAbstractBase as well: org.alfresco.repo.action.executer.MailActionExecuter
Here is sample code snippet using OOTB MailActionExecuter which may be helpful. |
---|
private String fromEmailAddress; //Setter and Getter methods of above items
//If you have person's user id, this method will get the email id via its person node and intitiate email action private String getMailTemplate(final String templateString) throws SendMailException { private NodeRef getTemplatesSpace() throws SendMailException {
final List<NodeRef> selectedNodes = searchService.selectNodes(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE),
|
Someone has implemented a custom MailExecutorAction by taking the reference of OOTB action class which can send the attachments as well. I have not tested it but you may want to try this: https://community.alfresco.com/docs/DOC-6574-send-html-mail-with-attachments
Hi Abhinav,
i want to send a mail using inbound ACS setting to any user .So i used ActionExecuterAbstractBase to send a mail .
Instead of creating traditional email sender logic/methods and implementing the action. I would suggest to use OOTB way of sending emails. It is also an action which can be executed synchronously/asynchronously. You can use a custom email template with this approach where you can pass some parameters, add custom logo and format as per your liking. It will also support sending email to an Alfresco Group. e.g. GROUP_Administrators. If you pass this value, all the users who are part of this group would receive emails. You don't have to extract each user's email id..
Any configuration i have to do for from , host and port in alfresco global properties
Yes. you would need following configurations:
mail.host=smtp.xyz.com
mail.port=25
mail.encoding=UTF-8
mail.from.default=alfresco-local@xyz.com
You can bootstratp your email templates to /Company Home/Data Dictionary/Email Templates/ folder and get the template at run time while sending email. You can refer here for bootstrapping template: https://docs.alfresco.com/4.2/concepts/dev-extensions-modules-bootstrapping-files-spaces-xml.html
You can find the ootb email templates in /Company Home/Data Dictionary/Email Templates/ folder and you can take reference from any of the templates to create your custom template if needed.
The sample method provided above: getMailTemplate(final String templateString) needs the name of the template file and it returns the full path for the method which uses the template for sending email..
e.g. getMailTemplate("my_operation_email.html.ftl")
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setExecuteAsynchronously(false);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, to);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, subject);
actionService.executeAction(mailAction, null);
I am not getting any error . But mail is not going
Can you please check all log files including catalina.out log as well. Enable these debug logs and try again to see what error you can find:
log4j.logger.org.alfresco.repo.action=debug
log4j.logger.org.alfresco.repo.action.executer.MailActionExecuter=debug
Make sure you are not catching any generic exception somewhere which may not be logged.
To Send Email,you need to unable outbound email configuration.
https://docs.alfresco.com/6.1/concepts/email.html
Ex.
mail.host=smtp.gmail.com
mail.port=465
mail.encoding=UTF-8
mail.username=xxx@gmail.com
mail.password=xxxx
mail.protocol=smtps
ActionService actionService = serviceRegistry.getActionService();
Action mailAction = actionService.createAction(MailActionExecuter.NAME);
mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, subject);
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, email);
actionService.executeAction(mailAction, null);
xxx@gmail.com This account must be less sucure app.
https://myaccount.google.com/lesssecureapps
Thanks,
Sanjay Bandhniya
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.