Problem sending mail with attachment using AngularJS
I am using Angular. When I send a mail with attachment to email, the response was that I received the data code of the file instead its actual file format.
like this:
I don't know what's the problem.
here's the code :
html :
<div class="uploadfile">
<input fileread="formData.attached" (change)="onFileSelected" type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">Upload CV</button>
<span id="custom-text">No file chosen, yet.</span>
</div>
<!--Script upload -->
<script>
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[/\]([wds.-()]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
</script>
<!--End of Script upload -->
app.js :
myApp.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
}
}]);
Hope you can help.
Thanks in advance.
javascript html css angular
add a comment |
I am using Angular. When I send a mail with attachment to email, the response was that I received the data code of the file instead its actual file format.
like this:
I don't know what's the problem.
here's the code :
html :
<div class="uploadfile">
<input fileread="formData.attached" (change)="onFileSelected" type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">Upload CV</button>
<span id="custom-text">No file chosen, yet.</span>
</div>
<!--Script upload -->
<script>
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[/\]([wds.-()]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
</script>
<!--End of Script upload -->
app.js :
myApp.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
}
}]);
Hope you can help.
Thanks in advance.
javascript html css angular
add a comment |
I am using Angular. When I send a mail with attachment to email, the response was that I received the data code of the file instead its actual file format.
like this:
I don't know what's the problem.
here's the code :
html :
<div class="uploadfile">
<input fileread="formData.attached" (change)="onFileSelected" type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">Upload CV</button>
<span id="custom-text">No file chosen, yet.</span>
</div>
<!--Script upload -->
<script>
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[/\]([wds.-()]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
</script>
<!--End of Script upload -->
app.js :
myApp.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
}
}]);
Hope you can help.
Thanks in advance.
javascript html css angular
I am using Angular. When I send a mail with attachment to email, the response was that I received the data code of the file instead its actual file format.
like this:
I don't know what's the problem.
here's the code :
html :
<div class="uploadfile">
<input fileread="formData.attached" (change)="onFileSelected" type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">Upload CV</button>
<span id="custom-text">No file chosen, yet.</span>
</div>
<!--Script upload -->
<script>
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value.match(
/[/\]([wds.-()]+)$/
)[1];
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
</script>
<!--End of Script upload -->
app.js :
myApp.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
}
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
}
}]);
Hope you can help.
Thanks in advance.
javascript html css angular
javascript html css angular
edited Jan 3 at 12:21
wanttobeprofessional
1,03131323
1,03131323
asked Jan 2 at 3:02
d.unknownd.unknown
14
14
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
In the image you attached, I saw that the file is actually 64 based string. So the problem is from your Angular Code.
reader.readAsDataURL(changeEvent.target.files[0]);
readAsDataURL will return the base64 encoded string. You can check the link here FileReader.readAsDataURL()
As the result, you just receive the string in your email, but not actual file. So you should specify file name and encoding = base64.
I'm not sure that technology in the back end that you are using. You can check the sample nodeJs code here.
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000765%2fproblem-sending-mail-with-attachment-using-angularjs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In the image you attached, I saw that the file is actually 64 based string. So the problem is from your Angular Code.
reader.readAsDataURL(changeEvent.target.files[0]);
readAsDataURL will return the base64 encoded string. You can check the link here FileReader.readAsDataURL()
As the result, you just receive the string in your email, but not actual file. So you should specify file name and encoding = base64.
I'm not sure that technology in the back end that you are using. You can check the sample nodeJs code here.
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
add a comment |
In the image you attached, I saw that the file is actually 64 based string. So the problem is from your Angular Code.
reader.readAsDataURL(changeEvent.target.files[0]);
readAsDataURL will return the base64 encoded string. You can check the link here FileReader.readAsDataURL()
As the result, you just receive the string in your email, but not actual file. So you should specify file name and encoding = base64.
I'm not sure that technology in the back end that you are using. You can check the sample nodeJs code here.
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
add a comment |
In the image you attached, I saw that the file is actually 64 based string. So the problem is from your Angular Code.
reader.readAsDataURL(changeEvent.target.files[0]);
readAsDataURL will return the base64 encoded string. You can check the link here FileReader.readAsDataURL()
As the result, you just receive the string in your email, but not actual file. So you should specify file name and encoding = base64.
I'm not sure that technology in the back end that you are using. You can check the sample nodeJs code here.
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
In the image you attached, I saw that the file is actually 64 based string. So the problem is from your Angular Code.
reader.readAsDataURL(changeEvent.target.files[0]);
readAsDataURL will return the base64 encoded string. You can check the link here FileReader.readAsDataURL()
As the result, you just receive the string in your email, but not actual file. So you should specify file name and encoding = base64.
I'm not sure that technology in the back end that you are using. You can check the sample nodeJs code here.
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
const mailOptions = {
...
attachments: [
{ // encoded string as an attachment
filename: yourFileName,
content: fileString,
encoding: 'base64'
}
]
};
answered Jan 3 at 8:54
Nguyen Manh TungNguyen Manh Tung
6
6
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
add a comment |
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
Hi, thank you so much for answering, I'm still new in coding maybe you can also check my backend code here : $scope.formData = { type:'careers', name : '', contact : '', email : '', position : '', attached : '', }; I still don't make it work :(, Thank you so much!
– d.unknown
Jan 8 at 9:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000765%2fproblem-sending-mail-with-attachment-using-angularjs%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown