ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do you send an HTML email? I always assumed that if you designed a web page and put it in a plain text email that the client would detect the <html> tag and display it appropriately. Evidently not. I need to know what to enter into a plain text email so that the receiving email client will interpret the markup.
I believe HTML e-mails generally have a header specifying that it is a Content-Type of HTML. Depending on your e-mail client, there is probably an option somewhere to specify if you want to send HTML or plain text e-mails, and then it will set the header appropriately.
Ok, then what API, object, whatever are you using to send the e-mail? Many of them I have used have a way of specifying that you want to send the mail in an HTML format. Or are you just connecting with a socket to an SMTP server and doing all the protocol work yourself?
The following would be the conversation which takes place with the SMTP server to send a simple HTML e-mail:
Code:
HELO: email-client
250 good
MAIL FROM: test@testaddress.com250 good
RCPT TO: toemail@test.com250 good
DATA
354 start mail input
To: Joe Bloggs <joeb@test.com>
From: Test <test@test.com>
Subject: Test HTML E-mail
Content-Type: multipart/mixed; boundary = 1000010000
MIME-Version: 1.0
This is a MIME encoded message.
--1000010000
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: base64
PGh0bWw+CjxoZWFkPgo8L2hlYWQ+Cjxib2R5Pgo8YSBo
cmVmPSJ3d3cubXlsaW5rLmNvbSI+dGVzdCBsaW5rPC9h
Pi4gCjxoMT5UaGlzIGlzIGEgdGVzdCBlLW1haWwgc2Vu
dCBpbiBodG1sIGZvcm1hdDwvaDE+CjwvYm9keT4KPC9od
G1sPg==--
.
250 mail queued for delivery
QUIT
The bits in bold are what the SMTP server says. Its usually good practice to encode content. The base 64 encoded part of the message reads:
Code:
<html>
<head>
</head>
<body>
<a href="www.mylink.com">test link</a>.
<h1>This is a test e-mail sent in html format</h1>
</body>
</html>
The above dialogue will work if you connect directly to an SMTP server. If you replace the address in the RCPT TO line with your own email address you should reiceve a nice HTML e-mail in your mail box.
I was using PHP to send the email. The book I was using didn't cover HTML email but I found what I needed on the PHP website. Basically I needed to add:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.