Author | Forum: General Questions Topic: PRB: How do I send an HTML message like Outlook does? |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted May 24, 2002 1:11 PM The following was originally a KnowledgeBase article from an older version of our Support Forum: Symptoms: Outlook express always sends me messages in HTML. How do I accomplish this using the PowerTCP Mail tool? Cause: Resolution: While the Mail Tool will not encode HTML, there is a way to send an HTML message, provided that you can supply the HTML. See the following code. to use create a new VB Project and put an SMTP control and a Command button on the form. Edit the constants that are declared at the top and run the program: Option Explicit Const Sender = "" Const Recipient = "" Const Server = "" Private Sub Command1_Click() On Error GoTo OnError Command1.Enabled = False TestStub GoTo Done OnError: Debug.Print "ERROR #" + CStr(Err.Number) + ": " + Err.Description Done: Command1.Enabled = True End Sub Private Sub TestStub() Smtp1.Message.Content = "" Smtp1.To.Add Recipient Smtp1.From = Sender Smtp1.Message.To.Add Recipient Smtp1.Message.From = Sender Smtp1.Message.Subject = "Test HTML" ' Add the HTML part of the message Dim p As Part Set p = New Part p.Data = HTMLMessage p.Header.Clear p.Header.Add msgContentType, "text/html; charset=""iso-8859-1""" p.Header.Add msgEncoding, "quoted-printable" Smtp1.Message.Parts.Add p Set p = New Part p.Data = TextMessage p.Header.Clear p.Header.Add msgContentType, "text/plain" Smtp1.Message.Parts.Add p Smtp1.Message.Header.Add msgContentType, "multipart/alternative" Smtp1.Login Server Smtp1.Send Smtp1.Logout End Sub Private Function HTMLMessage() As String Dim s As String s = "<HTML><CENTER><FONT color=#800000 face=Arial size=7>" s = s + "Hello World!" s = s + "</FONT></CENTER></BODY></HTML>" HTMLMessage = s End Function Private Function TextMessage() As String TextMessage = "Hello World" End Function Private Sub Form_Load() If Recipient = "" Or Sender = "" Then MsgBox "Constants Not Set in Code!" Unload Me End If End Sub More Info: |
chrisc@oceangroup.net From: Cincinnati, OH USA Posts: 4 Member Since: 10/08/02 |
posted October 8, 2002 3:43 PM How's about a C# .NET version of this please? |
K M Drake![]() From: Utica, NY USA Posts: 3406 Member Since: 07/14/00 |
posted October 8, 2002 5:11 PM Hi, There is a new Message.AddHtml method that should make creating HTML mail easier for you. www.dart.com/downloads/update.exe If you are a C# user, you may want to consider our Mail.NET product (which has a similar method). Also, if you are interested in a custom C# sample, please contact us at sales@dart.com. -ken |
chrisc@oceangroup.net From: Cincinnati, OH USA Posts: 4 Member Since: 10/08/02 |
posted October 8, 2002 5:21 PM I'm using the DotNet product. Trying to get multipart/alternate to work. Could do it in the old Com product by adding message parts to a message part, setting the headers accordingly. Don't know the incantation for this product. |
chrisc@oceangroup.net From: Cincinnati, OH USA Posts: 4 Member Since: 10/08/02 |
posted October 8, 2002 5:25 PM I'm reading a couple of files (templates) into strings, doing some substitution and assigning the strings to MessagePartStreams. One is HTML and One is plain/text. Setting the message header to multipart/alternative and the content types for each part to their respective type (html and plain). No go. |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted October 9, 2002 10:01 AM Have you tried using the MessageStream constructor which automatically constructs an HTML email? This is discussed in the PowerTCP Mail for .NET documentation. See ms-help://PowerTCPMail/PowerTCPMail/topics/SendingMailHTML.htm (topic name: Sending Html Email) in the docs. If this is not what you are looking for, please elaborate on what you are trying to do when you say "I'm reading a couple of files (templates) into strings, doing some substitution and assigning the strings to MessagePartStreams." Is this in an attempt to create a message containing multiple HTML files? |
chrisc@oceangroup.net From: Cincinnati, OH USA Posts: 4 Member Since: 10/08/02 |
posted October 10, 2002 9:16 AM I'm trying to accomplish the same functionality as the lead in this thread from Tony...multipart/alternative. Right now, I'm unclear as to how to contruct the message to get proper placement of the headers(in C#). I am aware of the HTML constructor, but that doesn't help me with the text alternative. Hope the above is more clear. Currently I have the HTML popping up just fine, but the text is coming as an attachment. |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted October 14, 2002 9:15 AM The MessageStream constructor by default creates an HTML part, then "strips" the text from the HTML and adds it as a text part. If you want to add a different text part instead of the "stripped out" HTML, the following worked for me. // Create HTML ready email MessageStream msg = new MessageStream("C:\\html\\myfile.html"); // Replace the text part. msg.Parts.Complex[0].Text = "This is my replacement text"; msg.To.Add(new MailAddress("jeff@dart.com")); msg.From = new MailAddress("test@dart.com"); msg.Subject = "HTML Mail"; smtp1.Server = "mail"; try { smtp1.Send(msg); MessageBox.Show("Done"); } catch(Exception ex) { MessageBox.Show(ex.Message); } Let me know if this is what you are looking for. |
Paulata From: Cuernavaca, Mexico Posts: 3 Member Since: 01/16/03 |
posted January 16, 2003 11:55 AM Which references should I add to send an email with HTML BOdy format? ... i'm using vb6 and I want to send an activereports in HTML format... Thanx |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted January 16, 2003 5:39 PM Do you have the latest dll updates for this product ( www.dart.com/download/update.exe )? If so, simply add the component to a form or dim a reference to DartMail.dll. Then use the Message.AddHtml method to create an HTML message. |
Paulata From: Cuernavaca, Mexico Posts: 3 Member Since: 01/16/03 |
posted January 17, 2003 1:03 PM Thanx for your answer... now I have another question: How can I send an email with an specific address, for example, www.yahoo.com in your Outlook Inbox, exactly the page, with links and pics saved in your Inbox... ????? I'll be pleased if you answer me... |
Jeff Cranford![]() From: Rome, NY USA Posts: 586 Member Since: 05/30/01 |
posted January 17, 2003 1:16 PM You can do this 1 of 2 ways. 1) Use your browser to save the web page (in IE, File -> Save As). Then load it into the Message object using the AddHtml method. 2) If you need to do this within an application, you could use the Web Tool or Web Enterprise Tool to grab the html and images needed to construct an HTML message. We have an online sample which basically does this at http://samples.dart.com/samples/htmail.asp . |
Reply | General Questions Topics | Forums |
This site is powered by
![]() |