Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending HTML Formatted EMAILS from VB

Status
Not open for further replies.

JWhyte

Programmer
Feb 8, 1999
25
0
0
GB
I am sure some enlightened person will be able to help me out with this, so here goes.

I am attempting to write an application in VB that can send an EMAIL to any of my contacts in HTML format, rather like what can be achieved using Outlook Express.

I have experiemented with MAPI controls and can send PlainText OK, but when I try and send the text as HTML it simply sends the HTML source.

Any pointers to how this could be achieved or example sites would be most useful. By the way I have trawled through MSDN with no avail.

Heres hoping .......... John Whyte
jwhyte@skipton.co.uk
 
Ay,
Change the bodytype or contenttype property to "text/html" for the mail object before u call the send method
 
As far as I can tell there is no bodytype or contenttype property for the MAPI controls. So how would I do this? John Whyte
jwhyte@skipton.co.uk
 
JWhite,

I would be happy to be able to send e-mail " ... like outlook express .... ". since you appear to be able to do this, I would appreciate some pointers, routine ...


TIA


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Michael,

this is an example of what I have achieved so far. Please bare in mind OutLook Express is my default Mail program.

In VB add component Microsoft MAPI Controls to your project. The add a MAPIMessages control to your form. Then code as follows:

Code:
With MAPIMessages1
 .Compose
 .RecipAddress = &quot;<email address you wish to send to>&quot;
 .MsgSubject = &quot;<subject heading for EMAIL>&quot;
 .MsgNoteText = &quot;<actual text of EMAIL>&quot;
 .Send False
End With

This code works OK for me. My issue as described in earlier post, is that instead of sending the <actual text of EMAIL>, I wish to send HTML that will be recieved and formatted accordingly by the EMAIL recipient, a la DEVX EMAIL newsletters.

I hope this is of help to you.
John Whyte
jwhyte@skipton.co.uk
 
John,

Thanks - again - I will try this today and see if I can get it to work.


MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
For anybody who is interested I have come across a component called HTMLMailer by a company called OOPadelic that fulfills all the requirements I raised here.

John Whyte
jwhyte@skipton.co.uk
 
And I think the important point is that is is free!! Peter Meachem
peter@accuflight.com
 
Dear John Whyte,

I am interested in knowing more about the HTML mailer component. Can u please pass me more info ?

Apoorva
 
It's at There is a free version that does not allow attachments, and a $45 one that does. It requires you to supply the smtp server name, and I haven't yet found out how to discover this on a clients pc.

Asie from that, I've sent myself an email with it, so it works to that extent. Peter Meachem
peter@accuflight.com
 
Hi All

Here are some code to send HTML using the Winsock Control.
This should get you going.........

Option Explicit
Dim bWaitForData As Boolean
Private Sub cmdSend_Click()
List1.Clear
Winsock1.Connect
DoWait
Winsock1.SendData &quot;HELO &quot; & Winsock1.LocalHostName & vbCrLf
DoWait
Winsock1.SendData &quot;MAIL FROM:<cdt@icon.co.za>&quot; & vbCrLf
DoWait
Winsock1.SendData &quot;RCPT TO:<cdutoit@exponant.com>&quot; & vbCrLf
DoWait
Winsock1.SendData &quot;DATA&quot; & vbCrLf
DoWait
Winsock1.SendData &quot;From: Carel du Toit<cdt@icon.co.za>&quot; & vbCrLf & _
&quot;To: (Carel du Toit (Exponant))<cdutoit@exponant.com>&quot; & vbCrLf & _
&quot;Subject: Test HTML Mail From VB&quot; & vbCrLf & _
&quot;X-Mailer: MyMail&quot; & vbCrLf & _
&quot;Mime-Version: 1.0&quot; & vbCrLf & _
&quot;Content-Type: text/html;&quot; & vbTab & _
&quot;charset=us-ascii&quot; & vbCrLf & vbCrLf & _
&quot;<TABLE BORDER=1><TR><TH><Email To>This Code was done by Toyman</TR>&quot; & _
&quot;<TR><TD><a href=mailto:cdt@icon.co.za>Email Toyman</TR></TABLE>&quot; & vbCrLf
Winsock1.SendData &quot;.&quot; & vbCrLf
DoWait
Winsock1.SendData &quot;QUIT&quot; & vbCrLf
Winsock1.Close
End Sub
Private Sub Form_Load()
With Winsock1
.RemoteHost = &quot;your smtp server&quot;
.RemotePort = 25
End With
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData
List1.AddItem strData
bWaitForData = True
End Sub
Private Sub DoWait()
While Not bWaitForData
DoEvents
Wend
bWaitForData = False
End Sub
Toyman
VB Programmer
cdt@icon.co.za
 
OK, couple of points. CDO for Windows 2000 has the ability to the bodytype, as suggested by SrikanthMc, as does CDONTS. Prior versions do not. And VB's MAPI controls sure a heck don't. There's a nice MS knowledgebase article on the subject here:
Now, without going into the hows or whys, you need to be aware that an Outlook message is generally split into two parts: a plain text part, and an RTF part. The MAPI controls only give you access to the plain text part.

Fortunately, Microsoft have an additional DLL available ( that allows you to read and write the RTF part.

Why would you want to do this? Because, if you read the first knowledgebase article I mention you'll note that the way Outlook actually sends HTML is by embedding it in an RTF stream.
So, get hold of the DLL, and read the documentation on how to use it to write the RTF part of a message.

Then, theoretically, you can build your RTF/HTML stream with something as simple as:

strRTFStream = &quot;\fromhtml1&quot; & strHTMLStream

and then squirt it into the RTF part of the message via the DLL.


On the other hand, you may want to stick to using a third-party control...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top