I am learning AEM and I am working on a requirement where in I am able to send email message however I am unable to add attachments that are browsed from my machine.
Requirement -
There is a form made in HTML from where info is collected and there is a browse button from where a file can be uploaded.
As soon as the file is uploaded an email should be sent to an email address with form content and with the attachment.
Also at the same time, through a POST request the form content and the attachement should be sent to a JSON
Sending the content via email to the receipient and to the POST method is working fine.
Any suggestions on how can I get attachement working in this ?
Thanks!
In HTML, You can fetch the file from input box with type "file" as ::
<form id="submitForm" action="/bin/servlets/submitForm" method="POST" novalidate="novalidate" enctype="multipart/form-data">
<label for="name">Name </label><input name="userName" type="text" class="fieldInner" id="name" required>
<input name="file" value="Choose File" type="file" class="chooseFileInner" required/>
<input type="submit" id="applied" value="Submit"/>
</form>
in java, you can fetch this file as ::
RequestParameter attach = request.getRequestParameter("file");
InputStream ip = attach.getInputStream();
MailTemplate mailTemplate = MailTemplate.create(templatePath, session);
HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(new HashMap<String, String>(parameters)), HtmlEmail.class);
ByteArrayDataSource fileDS = new ByteArrayDataSource(ip, "application/pdf");
email.attach(fileDS, "application/pdf", "This is your attached file.");
messageGateway = messageGatewayService.getGateway(HtmlEmail.class);
messageGateway.send(email);
You can also refer this Link to send images in email in aem
Related
The email address I am attempting to send to is one provided / hosted on 123-reg.
I received emails to that address if sent from my personal email, and I can also send emails back from within that inbox.
I have tested the contact form to make sure it works by first inputting my personal email address, and I receive the activation email as usual and once activated, can received contact sent via the contact form, directly to my personal email address.
However, when I use the email provided via 123reg, I don't receive the activation email at all. I've also checked spam folder, but nothing there either.
For anyone unfamiliar with formsubmit, here is the link: https://formsubmit.co/ -- what you see in the demo is pretty much all it takes to get a contact form set up. I've tried contacting them directly but it's been about a week or 2 and yet to receive a response.
If anyone can help, or suggest anything to help me figure out why it's not working it'd be much appreciated!
According to my knowledge, this is something you have to check with your email service provider. Because you have received FormSubmit emails into your personal email address, so the issue might be with the 123-reg.
Please try to contact them to get some support.
This answer works. Remember to replace your email with the string sent in the activation email before you click on Activate.
<form class="i-form" action="https://formsubmit.co/youremail#gmail.com" method="POST">
<!--optional starts--> <input type="hidden" name="_url" value="https://youremail#gmail.com/thepage.html"> <!--optional ends-->
<label for="name">Name</label>
<input type="text" id="name" name="name" class="i-email">
<br>
<label for="email">Email</label>
<input type="email" id="email" name="i-email" class="i-email">
<br>
<input type="submit" value="Get started">
</form>
Form activated
Form submitted by other user
User inputted submitted via form received in my inbox
I am new to AMP for Email and I am trying to create some interactive forms to be send as Email to my customers. Now I am facing an issue in the linked drop down implementation in AMP for Email. My requirement is based on the country drop down selection I have to fill the city drop down for my users to select their city.
But as per the documentation in <amp-list>
Binding to the [src] attribute is not allowed.
So how can I do my linked drop down functionalities in my amp for email
Please suggest!
One solution is to use amp-form instead of amp-list and bind to a hidden input element:
<form id="myForm" method="post" action-xhr="https://example.com">
<input type="hidden" name="param" value="" [value]="state.param">
<div submit-success>
<template type="amp-mustache">
<!-- your server response template -->
</template>
</div>
</form>
<button on="tap:AMP.setState({ state: { param: 'hello' } }), myForm.submit">Bind</button>
Also see the Advanced Server Request example on amp.dev: it demonstrates how you can replace an amp-list with an amp-form seamlessly on user interaction.
I'm trying to allow my users to upload a videos. My channel has "file" as the first channel field.
Made a channel form with the following code. When I try to upload anything I get the error field_id_5 is a required field (this is my file field). The only way i get the form to go through is if I make the video file not require, in which case all the other info goes through.
WHen i create a post in this channel through the EE control panel, it works. Video file is uploaded and all and it shows up in my channel in the video player.
Any help? Very new to coding so it may be a very simple mistake somewhere.. apologies :)
I managed to get it working with {field:video_file} instead of input tags but then I can't control what types of files they can send...
{exp:channel:form channel="video_post_uploaded"}
<p class="form_text">Post Title:
<br><input type="text" name="title" id="title" value="{title}" onkeyup="liveUrlTitle();" class="form_input">
<!-- <p>URL Title: -->
<br><input type="hidden" id="url_title" name="url_title" value="{url_title}" class="form_input">
<!-- <p class="instructions">Don't worry about this one, it fills itself out automatically. -->
<p>Upload Video:
<p><input type="file" name="video_file">
<p class="instructions">{instructions:video_file}
<p>Game:
<br><select name="game_title_uploaded">
{options:game_title_uploaded}
<option value="{option_value}"{selected}>{option_name}</option>
{/options:game_title_uploaded}
</select>
<p class="instructions">{instructions:game_title_uploaded}
{status_menu}
<select name="status" class="hidden">
{select_options}
</select>
{/status_menu}
<p><input type="submit" value="Post It!" class="submit_button">
{/exp:channel:form}
You cannot use it with just input type file. EE needs another hidden field to indicate directory of file to upload.
You can use it like this:
<input type="file" name="video_file">
<input type="hidden" name="video_file_directory" value="1">
I have tried a form submit with files example all the files are getting uploaded to XTRF and getting the response.
Now I am using blueimp jquery file uploader[http://blueimp.github.io/jQuery-File-Upload/]. If I upload image files it is getting uploaded to XTRF. If I upload any other files it is not getting uploaded to XTRF. I am getting workfile.rtf as response with junk data.
Please help me in solving this issue.
Need to upload files to XTRF using ajax uploader.
POST /system/session/files
Accepts files encoded as multipart/form-data and stores them temporarily (they are available only within current session). Each file gets its own id and basic statistics: number of characters (with and without spaces), words, lines, pages.
sample html form for file upload
<form id="upload" action="baseURL/system/session/files" method="post" enctype="multipart/form-data">
<label>Select a file:</label>
<input type="file" name="file" size="45"></input>
<input type="submit" value="Upload"></input>
</form>
You can also send plain text assigned to parameter content encoded as application/x-www-form-urlencoded. Such text will be stored as uploaded file.
sample html form that sends text for upload
<form id="sourceText" action="baseUrl/system/session/files" method="post" enctype="application/x-www-form-urlencoded">
<label>Source text:</label>
<textarea name="content" rows="5" columns="40"></textarea>
<input type="submit" value="Save"></input>
</form>
Uploaded files can be attached to quote request or while updating user's profile.
In my webapplication, a JSP page outputs to the webpage, the list of users logged in that day. I want to mail the same output to specifics mail-ids. What all Struts2 tags do I need to use?
Grab the HTML using JavaScript and send it as request parameter.
<div id="content">
... (here you should put content which you'd like to mail)
</div>
<form action="mail" method="post" onsubmit="html.value = encodeURIComponent(document.getElementById('content').innerHTML)">
<input type="hidden" name="html" />
<input type="submit" value="Mail this document" />
</form>
It'll be available as request parameter with name "html" in Struts2/Servlet side. The emailing job can be done with help of JavaMail.