How can I send email with attachment xls file using shell script as application/xls mimetype without making...
#!/bin/bash
ATTACH1=file.xls<br>
SUBJECT="subj"<br>
FROM=me@domain.com<br>
TO=you@domain.com<br>
CC=them@domain.com<br>
MIME="Application/vnd.ms-excel" <br>
FILE=$ATTACH1<br>
boundary="---my-unlikely-text-for-mime-boundary---$$--" <br>
(cat <<!<br>
From: $FROM<br>
To: $TO<br>
Subject: $SUBJECT<br>
Date: $(date +"%a, %b %e %Y %T %z")<br>
Mime-Version: 1.0<br>
Content-Type: multipart/mixed; boundary="$boundary"<br>
This email has attached the file<br>
--$boundary<br>
Content-Type: $MIME;name="$FILE"<br>
Content-Disposition: attachment;filename="$FILE"<br>
!<br>
uuencode ${ATTACH1} ${ATTACH1}<br>
) | sendmail -v ${TO}<br>
Hi,
The above code can send xls file using shell script. But the problem is that, the received file cant be open. Also, the file size of the xls becomes smaller. Example: original xls attachment size is 17kb before sending, but the received file becomes 378b in size after it was sent..
What can I do to make the xls that was received becomes readable when open by the receiver? What is wrong or missing in the above script? Please help!!!!
And by the way.. I CANNOT USE MUTT
bash unix shell shell-script aix
|
show 1 more comment
#!/bin/bash
ATTACH1=file.xls<br>
SUBJECT="subj"<br>
FROM=me@domain.com<br>
TO=you@domain.com<br>
CC=them@domain.com<br>
MIME="Application/vnd.ms-excel" <br>
FILE=$ATTACH1<br>
boundary="---my-unlikely-text-for-mime-boundary---$$--" <br>
(cat <<!<br>
From: $FROM<br>
To: $TO<br>
Subject: $SUBJECT<br>
Date: $(date +"%a, %b %e %Y %T %z")<br>
Mime-Version: 1.0<br>
Content-Type: multipart/mixed; boundary="$boundary"<br>
This email has attached the file<br>
--$boundary<br>
Content-Type: $MIME;name="$FILE"<br>
Content-Disposition: attachment;filename="$FILE"<br>
!<br>
uuencode ${ATTACH1} ${ATTACH1}<br>
) | sendmail -v ${TO}<br>
Hi,
The above code can send xls file using shell script. But the problem is that, the received file cant be open. Also, the file size of the xls becomes smaller. Example: original xls attachment size is 17kb before sending, but the received file becomes 378b in size after it was sent..
What can I do to make the xls that was received becomes readable when open by the receiver? What is wrong or missing in the above script? Please help!!!!
And by the way.. I CANNOT USE MUTT
bash unix shell shell-script aix
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
No, I mean how does the data that gets piped intosendmail
contain the contents of the file you want to attach to the email?
– a CVn
Jan 15 '16 at 10:49
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35
|
show 1 more comment
#!/bin/bash
ATTACH1=file.xls<br>
SUBJECT="subj"<br>
FROM=me@domain.com<br>
TO=you@domain.com<br>
CC=them@domain.com<br>
MIME="Application/vnd.ms-excel" <br>
FILE=$ATTACH1<br>
boundary="---my-unlikely-text-for-mime-boundary---$$--" <br>
(cat <<!<br>
From: $FROM<br>
To: $TO<br>
Subject: $SUBJECT<br>
Date: $(date +"%a, %b %e %Y %T %z")<br>
Mime-Version: 1.0<br>
Content-Type: multipart/mixed; boundary="$boundary"<br>
This email has attached the file<br>
--$boundary<br>
Content-Type: $MIME;name="$FILE"<br>
Content-Disposition: attachment;filename="$FILE"<br>
!<br>
uuencode ${ATTACH1} ${ATTACH1}<br>
) | sendmail -v ${TO}<br>
Hi,
The above code can send xls file using shell script. But the problem is that, the received file cant be open. Also, the file size of the xls becomes smaller. Example: original xls attachment size is 17kb before sending, but the received file becomes 378b in size after it was sent..
What can I do to make the xls that was received becomes readable when open by the receiver? What is wrong or missing in the above script? Please help!!!!
And by the way.. I CANNOT USE MUTT
bash unix shell shell-script aix
#!/bin/bash
ATTACH1=file.xls<br>
SUBJECT="subj"<br>
FROM=me@domain.com<br>
TO=you@domain.com<br>
CC=them@domain.com<br>
MIME="Application/vnd.ms-excel" <br>
FILE=$ATTACH1<br>
boundary="---my-unlikely-text-for-mime-boundary---$$--" <br>
(cat <<!<br>
From: $FROM<br>
To: $TO<br>
Subject: $SUBJECT<br>
Date: $(date +"%a, %b %e %Y %T %z")<br>
Mime-Version: 1.0<br>
Content-Type: multipart/mixed; boundary="$boundary"<br>
This email has attached the file<br>
--$boundary<br>
Content-Type: $MIME;name="$FILE"<br>
Content-Disposition: attachment;filename="$FILE"<br>
!<br>
uuencode ${ATTACH1} ${ATTACH1}<br>
) | sendmail -v ${TO}<br>
Hi,
The above code can send xls file using shell script. But the problem is that, the received file cant be open. Also, the file size of the xls becomes smaller. Example: original xls attachment size is 17kb before sending, but the received file becomes 378b in size after it was sent..
What can I do to make the xls that was received becomes readable when open by the receiver? What is wrong or missing in the above script? Please help!!!!
And by the way.. I CANNOT USE MUTT
bash unix shell shell-script aix
bash unix shell shell-script aix
edited Jan 15 '16 at 14:45
scai
814617
814617
asked Jan 15 '16 at 10:15
RaymonNRaymonN
112
112
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
No, I mean how does the data that gets piped intosendmail
contain the contents of the file you want to attach to the email?
– a CVn
Jan 15 '16 at 10:49
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35
|
show 1 more comment
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
No, I mean how does the data that gets piped intosendmail
contain the contents of the file you want to attach to the email?
– a CVn
Jan 15 '16 at 10:49
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
No, I mean how does the data that gets piped into
sendmail
contain the contents of the file you want to attach to the email?– a CVn
Jan 15 '16 at 10:49
No, I mean how does the data that gets piped into
sendmail
contain the contents of the file you want to attach to the email?– a CVn
Jan 15 '16 at 10:49
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35
|
show 1 more comment
1 Answer
1
active
oldest
votes
You need to specify the Content-Transfer-Encoding for the MIME part with the attachment. I don't know if uuencode is a standard one. Base64 is though.
You also need to send the closing boundary marker.
Your redirection into cat is wrong.
(cat << !
From: $FROM
To: $TO
Subject: $SUBJECT
Date: $(date +"%a, %b %e %Y %T %z")
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
This email has attached the file
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
Please see the attachmed file.
--$boundary
Content-Transfer-Encoding: base64
Content-Type: $MIME;name="$ATTACH1"
Content-Disposition: attachment;filename="$ATTACH1"
$(base64 "$ATTACH1")
--$boundary--
!
) | sendmail -v "$TO"
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
TryContent-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.
– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f1026672%2fhow-can-i-send-email-with-attachment-xls-file-using-shell-script-as-application%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
You need to specify the Content-Transfer-Encoding for the MIME part with the attachment. I don't know if uuencode is a standard one. Base64 is though.
You also need to send the closing boundary marker.
Your redirection into cat is wrong.
(cat << !
From: $FROM
To: $TO
Subject: $SUBJECT
Date: $(date +"%a, %b %e %Y %T %z")
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
This email has attached the file
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
Please see the attachmed file.
--$boundary
Content-Transfer-Encoding: base64
Content-Type: $MIME;name="$ATTACH1"
Content-Disposition: attachment;filename="$ATTACH1"
$(base64 "$ATTACH1")
--$boundary--
!
) | sendmail -v "$TO"
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
TryContent-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.
– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
add a comment |
You need to specify the Content-Transfer-Encoding for the MIME part with the attachment. I don't know if uuencode is a standard one. Base64 is though.
You also need to send the closing boundary marker.
Your redirection into cat is wrong.
(cat << !
From: $FROM
To: $TO
Subject: $SUBJECT
Date: $(date +"%a, %b %e %Y %T %z")
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
This email has attached the file
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
Please see the attachmed file.
--$boundary
Content-Transfer-Encoding: base64
Content-Type: $MIME;name="$ATTACH1"
Content-Disposition: attachment;filename="$ATTACH1"
$(base64 "$ATTACH1")
--$boundary--
!
) | sendmail -v "$TO"
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
TryContent-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.
– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
add a comment |
You need to specify the Content-Transfer-Encoding for the MIME part with the attachment. I don't know if uuencode is a standard one. Base64 is though.
You also need to send the closing boundary marker.
Your redirection into cat is wrong.
(cat << !
From: $FROM
To: $TO
Subject: $SUBJECT
Date: $(date +"%a, %b %e %Y %T %z")
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
This email has attached the file
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
Please see the attachmed file.
--$boundary
Content-Transfer-Encoding: base64
Content-Type: $MIME;name="$ATTACH1"
Content-Disposition: attachment;filename="$ATTACH1"
$(base64 "$ATTACH1")
--$boundary--
!
) | sendmail -v "$TO"
You need to specify the Content-Transfer-Encoding for the MIME part with the attachment. I don't know if uuencode is a standard one. Base64 is though.
You also need to send the closing boundary marker.
Your redirection into cat is wrong.
(cat << !
From: $FROM
To: $TO
Subject: $SUBJECT
Date: $(date +"%a, %b %e %Y %T %z")
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="$boundary"
This email has attached the file
--$boundary
Content-Type: text/plain; charset=ISO-8859-1
Please see the attachmed file.
--$boundary
Content-Transfer-Encoding: base64
Content-Type: $MIME;name="$ATTACH1"
Content-Disposition: attachment;filename="$ATTACH1"
$(base64 "$ATTACH1")
--$boundary--
!
) | sendmail -v "$TO"
answered Jan 15 '16 at 11:41
glenn jackmanglenn jackman
16.2k32645
16.2k32645
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
TryContent-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.
– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
add a comment |
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
TryContent-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.
– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
base64: command not found :(
– RaymonN
Jan 15 '16 at 13:31
Try
Content-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.– glenn jackman
Jan 15 '16 at 14:32
Try
Content-Transfer-Encoding: uuencode
and use uuencode on the file like you were doing.– glenn jackman
Jan 15 '16 at 14:32
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
still not working..the attached file when received cannot be open
– RaymonN
Jan 15 '16 at 15:06
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f1026672%2fhow-can-i-send-email-with-attachment-xls-file-using-shell-script-as-application%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
Where are you putting the file content?
– a CVn
Jan 15 '16 at 10:43
you mean the code above? I put it in as script1.sh file then execute it by ./script1.sh
– RaymonN
Jan 15 '16 at 10:45
No, I mean how does the data that gets piped into
sendmail
contain the contents of the file you want to attach to the email?– a CVn
Jan 15 '16 at 10:49
Please see the updated script.. it now sends the same file size but now it contains begin 644 PRB0045758_EDI_UPLOAD_14-01-2016.xls M/#]X;6P@=F5R<VEO;CTB,2XP(C^"CQS<SI7;W)K8F]O:R!X;6QN<SIS<STB M=7)N.G-C:&5M87,M;6EC<F]S;V9T+6-O;3IO9F9I8V4Z<W!R96%D<VAE970B M/@H<W,Z4W1Y;&5S/@H<W,Z4W1Y;&4@<W,Z240](D]R86-L941A=&4B/@H M<W,Z3G5M8F5R1F]R;6%T('-S.D9O<FUA=#TB9&0O;6TO>7EY>5P@:&@Z;6TZ M<W,B+SX*/"]S<SI3='EL93X*/"]S<SI3='EL97,^"CQS<SI7;W)K<VAE970@
– RaymonN
Jan 15 '16 at 10:58
duplicate of stackoverflow.com/q/17359/7552
– glenn jackman
Jan 15 '16 at 11:35