wwSMTP::AddAlternateView

Allows adding an alternate view of the message that provides richer content. For example you may configure the main message as plain text and the alternate view as html including embedded images that are stored as part of the message.

This feature works only when nMailMode = 2 (.NET mode). If all you want is to create a plain text AND HTML message you can use the cAlternateText and cAlternateContentType which works in both modes. This method should be used only if you need to create more than two different alternate views, or if you want to embed images directly into the message content itself for self-contained image messages without external links.

Creating an alternate HTML View with Embedded Images

For example the following creates a simple message that has only a text marker for non-HTML clients and an HTML alternate view that contains a rich message and an embedded image to display in the message:

loSmtp.cSubject = "Test Message through wwIPstuff"
loSmtp.cMessage = "This message contains rich text content as an alternate view"
loSmtp.cContentType = "text/plain"

LOCAL loAlternateView as wwSmtpAlternateView
loAlternateView = CREATEOBJECT("wwSmtpAlternateView")
loAlternateView.cText = "<b>Hello</b> World! <img src='cid:sailbig' />"
loAlternateView.cContentType = "text/html"
loAlternateView.AddLinkedResource("c:\sailbig.jpg","image/jpeg","sailbig")
loSmtp.AddAlternateView( loAlternateView )

In this scenario any mail client that does not understand the main content type (text/html) will display the alternate view which is just plain text.

Embedded Linked Resources

Alternate views can also embed linked resources - that is resources that are embedded as part of the message and display inline of the message. By creating an wwSmtpAlternateView class and setting cText, cContentType on this object and then adding a linked resource this linked resource can be embedded directly into the message.

Linked Resources are added with a file path, a MIME content type and a resource Id (in this case 'sailbig'). This resource id can then be embedded and linked from the message text by using:

<img src="cid:sailbig"  />

inside of the message text.

o.AddAlternateView(loAlternateView)

Parameters

loAlternateView
An instance of the wwSmtpAlternateView class.

The class has the following properties and methods:

cText
The text of the alternate view message.

cContentType
The content type of the message. Default is plain/text, but common is text/html for rich content.

AddLinkedResource(lcFilename, lcContentType, lcContentId)
This method adds a related resource 'attachment' that is treated as an embedded resource that can be referenced from the cText property's html. Use to embed an image resource into the message.

Remarks

This feature only work with the .NET version of wwSMTP (nMailMode = 2).

Important: Although this feature is available the recommended way to get rich content to display is to use an HTML primary message text and link images from the Web into the message rather than embedding images directly into the email. This reduces mail traffic drastically.

Additionally keep in mind that not all mail clients support the embedded format, but most nowadays do support HTML messages.

Finally note that 'preview' displays in Outlook display the main message plain text, and the alternate view when the message is opened. This may or may not be desirable. Spend some time checking out how mail clients display this mixed content.


See also:

Class wwSMTP

© West Wind Technologies, 1996-2018 • Updated: 11/29/16
Comment or report problem with topic