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!

MAPI email with embedded image.

Status
Not open for further replies.

dantheinfoman

Programmer
May 5, 2015
131
US
Hi All,

My email system has an activex button that does the work of sending emails when needed. I need to send an image with certain emails. I've been successful in adding the image as an attachment, but I'm not sure how to EMBED the image so it's in the actual body of the email. Here's how the email works currently with an attachment:

Code:
local j, lnMaxLength, i, lcMessageText, lvFieldValue
** j & i are counters

private array paDBFields

*** Localizable Strings
#DEFINE DBF_NOT_FOUND_LOC	"No table is open in the current work area."
#DEFINE GEN_UNSUPPORT_LOC	"General fields are not supported in this example and will be skipped."
#DEFINE _FALSE_LOC			"FALSE"
#DEFINE _TRUE_LOC			"TRUE"
#DEFINE _NULL_LOC			"NULL"
#DEFINE _DOLLARSIGN_LOC		"$"
#DEFINE FLD_NO_PRINT_LOC	"Field could not be printed."
#DEFINE RECORDNUM_LOC		"Record #"


?"Checking Email"
* Verify that a table is open in the current work area
if empty(dbf())
	=messagebox(DBF_NOT_FOUND_LOC,48)
	return
else
	IF !this.parent.signon()			&& Use the custom method
		RETURN
	ENDIF
	IF this.parent.LogSession	&& Check if the user was able to login
		this.parent.OleMMess.sessionid=this.parent.OleMSess.sessionid
	
		* Get the number of fields in the current table
		=afields(paDBFields)

		**** find the longest field string for approximate formatting purposes
		lnMaxLength = 0
		for j = 1 to alen(paDBFields,1)
			if len(paDBFields(j,1))+2 > lnMaxLength
				lnMaxLength = len(paDBFields(j,1))+2
			endif
		endfor
	
		* Start a new mail message and build the text
		this.parent.OleMMess.compose
		lcMessageText=""
		for i = 1 to alen(paDBFields,1)
			lvFieldValue=alltrim(upper(paDBFields(i,1)))
			lcMessageText=lcMessageText+this.parent.addtabs((lvFieldValue+": "),lnMaxLength)
			if !isnull(&lvFieldValue)
				lcMessageText = m.subject
			else
				lcMessageText=lcMessageText+_NULL_LOC
			endif
		endfor
	IF EMPTY(m.vheader) 
		this.parent.OleMMess.msgnotetext=lcMessageText
		this.parent.OleMMess.msgsubject=m.subject
	ELSE 
		this.parent.OleMMess.msgsubject=m.vheader
		this.parent.OleMMess.msgnotetext=m.subject
	ENDIF
		****ds 10/13/16 test		
		IF !EMPTY(m.m_attfname)
			lnpos = 0  &&len(m_message) + 5
			this.parent.OleMMess.AttachmentIndex = 0
			this.parent.OleMMess.Attachmentposition = lnpos
			this.parent.OleMMess.AttachmentName = JUSTFNAME(M_ATTFNAME)
			this.parent.OleMMess.AttachmentPathname = alltrim(m_attfname)
		endif
		****

		*this.parent.OleMMess.msgsubject=m.subject
		this.parent.OleMMess.recipaddress=m.address
		this.parent.OleMMess.send 
		IF this.parent.logsession
			this.parent.OleMSess.signoff
		ENDIF	&& Session Handle test
	ENDIF 		&& Login Test
endif			&& DBF Test

I've seen some talk about utilizing HTML in emails in order to embed an image, but nothing's clear as to how I can accomplish this. My app doesn't need login credentials or 'smpt server' names or anything like that, it just sends a bunch of emails at a time as needed using Thunderbird automatically.

Anyone know what I can do to embed these?

Thanks

Dan
 
I never heard of an OleMMess object, seems like you are use the Microsoft MAPI Messages Control. It has no specific HTMLBody, but when I set MsgNoteText to HTML it's displayed as rendered HTML. With HTML you can do anything you want. Referring an image included in the mail needs an img tag with src="cid:identifier", which refers to a content id given to an attachment. It's simple to use in Outlook automation, as Outlook adds such a content id automatically for any attachment you add as the filename, that doesn't work as simple in an MS MAPI Message. I don't even see a way to add Mime Fields to an attachment via this simple mapi OLE control.

Bye, Olaf.

 
Thanks for the tip, Mike, unfortunately that didn't help. When looking at the source code of the created mail the file is still embedded as attachment (Content-Disposition: attachment;) instead of embedded (Content-Disposition: inline;) Besides it doesn't get a Content-ID.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top