2017-12-18 12 views
0

html로 전자 메일을 보내려고합니다.Linux 서버에서 전자 메일을 html로 보냄 - 전자 메일에도 내용 유형 및 html 태그가 표시됨

#!/bin/sh 

#MAIL_LIST="[email protected]" 
MAIL_SENDER=foo 

fnSendEmail(){ 
    echo ${BODY}| mail -r $MAIL_SENDER -s "$(echo "$MAIL_SUBJECT\nContent-Type: text/html")" "$MAIL_LIST" 
} 

MAIL_SUBJECT="Test email" 

BODY="<html><body><div><h2>Hi All</h2><hr></div></body></html>"; 

fnSendEmail $BODY $MAIL_SENDER $MAIL_SUBJECT $MAIL_LIST 

이메일을 수신하고 있지만 HTML 태그와 콘텐츠 유형은 다음과 같이 메일에도 표시됩니다.

주제

"Test email\nContent-Type: text/html" 

로 이메일 본문으로 :
<html><body><div><h2>Hi All</h2><hr></div></body></html> NOTICE TO RECIPIENT: If you are not the intended recipient of this e-mail, you are prohibited from sharing, copying, or otherwise using or disclosing its contents. If you have received this e-mail in error, please notify the sender immediately by reply e-mail and permanently delete this e-mail and any attachments without reading, forwarding or saving them. Thank you. 

사전에 콘텐츠 형식 헤더를 추가 할 -a

답변

0

사용 옵션을 주셔서 감사합니다, -s는 제목, 변경입니다 귀하의 fnSendEmail이 작동해야합니다.

fnSendEmail(){ 
    echo ${BODY}| mail -r $MAIL_SENDER -a "Content-type: text/html" -s "$(echo "$MAIL_SUBJECT\n")" "$MAIL_LIST" 
} 
+0

던지기를 사용했을 -> 콘텐츠 유형 : 텍스트/html로 : 해당 파일이나 디렉토리. 당신의 답변에 감사드립니다. 그러나 나는 여전히 정답을 찾고 있습니다. 동일한 코드가 다른 위치에서 작동합니다. 왜 그것이 여기에서 작동하지 않는지 나는 확신하지 못한다. –

+0

작은 'a'또는 자본 'A'를 시도 했습니까? 작은 'a'는 헤더와 자본을 추가하는 것입니다. 'A'는 첨부 파일을 추가하는 것입니다. 자본 A를 시도한 것 같습니다. 그런 파일이나 디렉토리가 없습니다. 작은 'a'를 시도하십시오. –

+0

작습니다. 방금 언급 한 위의 코드를 복사했습니다. –

0

나는 센드 메일

#MAIL_LIST1="[email protected]" 
MAIL_SENDER=dap 

fnSendEmail(){ 
(
    echo To: $MAIL_LIST 
    echo Cc: $MAIL_LIST 
    echo From: dap53 
    echo "Content-Type: text/html; " 
    echo Subject: $MAIL_SUBJECT 
    echo 
    echo $BODY 
) | /usr/sbin/sendmail -t 
} 

MAIL_SUBJECT="Test email" 
BODY="<html><body>Sample</body></html>" 

fnSendEmail $BODY $MAIL_SENDER $MAIL_SUBJECT $MAIL_LIST