2015-01-12 2 views
2

Gmail API를 사용하여 html 이메일을 보내려고하지만 몇 가지 이유로 이메일을 일반/텍스트로 무작위로 보냅니다. Google이 내가 설정 한 콘텐츠 형식 헤더를 변경하는 것 같습니다. 거기에 어떤 이유가 있습니까? 전자 메일 내용은 항상 똑같습니다 (테스트 할 때). API는 아직 실험 중입니까? 때로는 작동 할 때 Content-Type: multipart/alternative;을 추가합니다 (설정하지는 않았지만).Gmail API가 html 이메일을 일반 텍스트로 보내는 이유는 무엇입니까?

인코딩 프로세스는 다음과 같습니다. 코드는 Go이지만 자체적으로 설명이 가능하고 프로세스는 언어에 구애받지 않습니다.

header := make(map[string]string) 
    header["From"] = em.From.String() 
    header["To"] = em.To.String() 
// header["Subject"] = encodeRFC2047(em.Subject) 
    header["Subject"] = em.Subject 
    header["MIME-Version"] = "1.0" 
    header["Content-Type"] = "text/html; charset=\"utf-8\"" 
// header["Content-Transfer-Encoding"] = "base64" 
    header["Content-Transfer-Encoding"] = "quoted-printable" 
    var msg string 
    for k, v := range header { 
     msg += fmt.Sprintf("%s: %s\r\n", k, v) 
    } 

    msg += "\r\n" + em.Message 
    gmsg := gmail.Message{ 
     Raw: encodeWeb64String([]byte(msg)), 
    } 
    _, err = gmailService.Users.Messages.Send("me", &gmsg).Do() 
+1

질문은 http://stackoverflow.com/questions/26841905/sending-email-multipart-signed-rfc-3156-via-gmail-apis와 비슷합니다. – SGC

답변

1

흠, 프로그램에 버그가 없습니까? 전체 문자열을 인쇄하여 여기에 붙여 넣을 수 있습니까?

난 그냥 이메일 등을 보낼 수있는 Gmail의 API를 사용 :

 
To: <redacted> 
Subject: test html email 2015-01-14 09:45:40 
Content-type: text/html 

<html><body><b>hello</b>world</body></html> 

을 그리고 Gmail에서받는 사람의 말에 예상대로 보였다. 어떤 경우

 
<random trace headers> 
MIME-Version: 1.0 
From: <redacted> 
Date: Wed, 14 Jan 2015 09:46:41 -0800 
Message-ID: 
Subject: test html email 2015-01-14 09:45:40 
To: <redacted> 
Content-Type: multipart/alternative; boundary=089e0141a9a2875c38050ca05201 

--089e0141a9a2875c38050ca05201 
Content-Type: text/plain; charset=UTF-8 

*hello*world 

--089e0141a9a2875c38050ca05201 
Content-Type: text/html; charset=UTF-8 

<html><body><b>hello</b>world</body></html> 
--089e0141a9a2875c38050ca05201-- 

, 그것은 살균/몇 가지 분석을하고있어하지만을 않습니다 : 음, 실제로는 다중/대안에 싸서 및 (IMO 좋은 일이)뿐만 아니라 텍스트/일반 부분을 추가있어 보이는 text/html 이메일을 보낼 수 있습니다.

+1

답변에서 'content-type : text/html' 나를 도왔던 것이 었습니다. – Nakilon

관련 문제