이메일의 MIME Multipart
이메일에 이미지를 삽입하려고합니다.
이메일은 소켓을 통해 포트 25의 SMTP 서버로 데이터를 전송하여 생성됩니다. 다음은 MIME 비트입니다.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=mixedsection;
--mixedsection
Content-Type: text/plain;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Below should be an inline embedded image
--mixedsection
Content-Type: image/png; file=ts-charts.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAACk+hPgAAABpFBMVEX// (etc etc etc)
--mixedsection--
이메일을 받으면 두 번째 섹션 인 이미지가 첨부 파일로 변환되고 인라인으로 표시되지 않는 것으로 보입니다. 다른 모든 부분은 잘 작동하며 이미지는 첨부 파일을 열 수 있도록 base64로 올바르게 인코딩됩니다. 텍스트 / 일반 부분은 Content-Disposition이 인라인 또는 첨부 파일로 설정된 경우 모두 올바르게 작동합니다.
다른 메일 클라이언트 (outlook, thunderbird)를 사용하여 이미지를 포함했으며 이미지가 인라인으로 표시되는 데 문제가 없습니다.
다른 모든 것을 제거하더라도 이미지를 인라인으로 표시 할 수도 없습니다. 다음은 여전히 첨부 파일로 수신됩니다.
MIME-Version: 1.0
Content-Type: image/png; file=ts-charts.png
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAAC (etc etc)
그래서 질문은 내가 여기서 무엇을 놓치고 있으며 이미지를 인라인으로 표시하려면 어떻게해야합니까?
답변
어떤 이유에서인지 RFC 표준 방식에서 바로 바닐라로 작동하도록 만들 수 없었습니다. 그렇게 하는 방법 을 아는 사람이 있으면 게시 해주세요.
그래서 포기하고 인라인 HTML / CID를 사용하여 이미지를 삽입했습니다.
내가 한 방법은 다음과 같습니다.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=mixedsection;
--mixedsection
Content-Type: multipart/related; boundary=relatedsection;
--relatedsection
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 8Bit
Content-Disposition: inline
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<body>
<p><img src="cid:myembeddedimage" alt=""></p>
</body>
</html>
--relatedsection
Content-Type: image/png; name=ts-charts.png
Content-ID: myembeddedimage
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
iVBORw0KGgoAAAANSUhEUgAAAnoAAAHqCAMAAACk+hPgAAABpFBMVEX//3 (etc etc)
--relatedsection--
--mixedsection--
참고 :
Content-Type: image/png; file=ts-charts.png
파일 속성을 제거하고 이름 속성으로 대체하여 :
Content-Type: image/png; name=ts-charts.png
나는 이것이 좋은 방법이거나 권장되는 방법이라고 믿지 않지만 작동합니다.
편집 : .... 그냥 마무리합니다. 평범한 텍스트와 HTML 포함 이미지를 혼합하는 방법을 알아낼 수 없었기 때문에 단순히 텍스트를 HTML에 넣는 것을 선택했습니다.
마지막 메시지는 다음과 같습니다.
MIME-Version: 1.0
Content-Type: multipart/related; boundary=relatedsection;
--relatedsection
Content-Type: text/html;
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
<html>
<head>
<meta http-equiv="content-type" content="text/html;">
</head>
<body>
<p> Below is an embedded image ...</p>
<p><img src="cid:myembeddedimage" alt=""></p>
</body>
</html>
--relatedsection
Content-Type: image/png; name=ts-charts.png
Content-ID: myembeddedimage
Content-Transfer-Encoding: base64
Content-Disposition: inline; filename=ts-charts.png
AHqCAMAAACk+hPgAAABpFBMVEX///8PDw8jIyPDw8OPj333mOm2ajzGtEbdPpm (etc (etc)
--relatedsection--
이 메시지를 교환 서버를 통해 실행하면 첨부 파일 (att0001, att0002)이 메시지에 추가되므로 외부 멀티 파트 / 혼합을 제거해야했습니다. thunderbird, gmail 또는 i-Phone에서 클라이언트가 호출되는 모든 것에 대한 이러한 유령 첨부 파일에는 전혀 문제가 없습니다.