英文:
html not translated in email golang
问题
我正在尝试使用Golang和net/smtp库发送包含HTML内容的电子邮件。但是当我发送电子邮件时,HTML内容没有被转换,我收到的电子邮件内容如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
</head>
<body> <p>
Hello Louis
<a href="http://google.com/">Confirm email address</a> </p>
</body>
</html>
因为我的代码没有起作用,所以我尝试了[这个教程][1]。但是它也没有起作用。
所以,按照这个教程的示例,为什么我收到的电子邮件是字符串形式而不是格式化的HTML?
附注:我的代码与教程中的代码完全相同。
英文:
I'm actually trying to send email with html content with golang and net/smtp lib.
But when i send email, html is not translated and i receive an email like that :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html>
</head>
<body> <p>
Hello Louis
<a href="http://google.com/">Confirm email address</a> </p>
</body>
</html>
Because with my own code it did not work, i've tried with [this tutorial][1]
[1]: https://medium.com/@dhanushgopinath/sending-html-emails-using-templates-in-golang-9e953ca32f3d#.whzu9z3if
but it doesn't work either..
So with the example of this tutorial why i receive email in the form of string and not in formatted html ?
ps : My code is absolutely the same as in the tutorial
答案1
得分: 1
那个示例是错误的。在第46行,它有:
mime := "MIME-version: 1.0;\nContent-Type: text/plain; charset=\"UTF-8\";\n\n"
也就是 Content-Type: text/plain
。如果你发送的是 HTML 邮件,应该使用 Content-Type: text/html
。
英文:
That sample is wrong. On line 46, it has
mime := "MIME-version: 1.0;\nContent-Type: text/plain; charset=\"UTF-8\";\n\n"
Namely the Content-Type: text/plain
). If you're sending HTML mail, you should use Content-Type: text/html
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论