# jpg or HTML on email body

**URL:** <https://forum.servoy.com/t/jpg-or-html-on-email-body/10841>\
**Category:** Classic Servoy\
**Created:** [June 29, 2009, 2:32pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841 "2009-06-29T14:32:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuanMartin](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@JuanMartin](https://forum.servoy.com/u/JuanMartin)\
**Post date:** [June 29, 2009, 2:32pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/1 "2009-06-29T14:32:50Z")

</div>

Hi,  
I need send emails when the jpg or html are on email body.  
When I send email, all is ok but the jpg or HMT on email body don´t sent.  
What I refer to the jpg or html for this to be sent?

Thanks

---

<div class="post-metadata">

**Author:** ![sanneke](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@sanneke](https://forum.servoy.com/u/sanneke)\
**Post date:** [June 29, 2009, 2:50pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/2 "2009-06-29T14:50:15Z")

</div>

Hi JuanMartin,

This is a sample of how you can send a email with a inline image

```auto
var attachment1 = plugins.mail.createBinaryAttachment('embeddedImage',plugins.file.readFile('c:/nok.jpg'));
var msgText = 'plain msg<html>styled msg<img src="%%embeddedImage%%"></html>';
var success = plugins.mail.sendMail('tsdsddd@gmail.com', 'John Cobb <from_me@example.com>', 'subject', msgText,null,'unnamed@example.com',[attachment1]);
application.output(success)

```

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 7, 2009, 2:33pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/3 "2009-07-07T14:33:45Z")

</div>

Is there any way to get something like this to work in a html area?

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [July 7, 2009, 2:51pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/4 "2009-07-07T14:51:05Z")

</div>

What do you mean by getting something like this to work in a html area?

Maybe all you need is a method using this kind of code and add a link to trigger it?

```auto
<a href="javascript:sendEmailMethod()">send as email</a>

```

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 7, 2009, 6:57pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/5 "2009-07-07T18:57:10Z")

</div>

Sorry, I ment inline images in a HTML area.  
What we’d like to have is a crossplatform solution to display images in a HTML area, while the images are just in a shared folder on a clients fileserver. The difficulty of course is the path which will be different for mac and windows.  
As replacing won’t work in a mixed environment my thought was have an inline image solve this problem.

---

<div class="post-metadata">

**Author:** ![ptalbot](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/ptalbot/32/4952_2.png) [@ptalbot](https://forum.servoy.com/u/ptalbot)\
**Post date:** [July 7, 2009, 7:05pm UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/6 "2009-07-07T19:05:53Z")

</div>

Doesn’t this work for you as a provider for a text field with displayType = HTML\_AREA?

```auto
var img = '<html><body><img src="media:///myInlineImage.gif"></body></html>';

```

**[EDIT]**  
Sorry Marc, I just realize what you meant.  
I just tried it and it works fine in developer and server smart and web clients (quick and dirty example, you might want to add error handling):

```auto
var img = getMyInlineImageData(); // variable shoud be of type MEDIA!

function getMyInlineImageData()
{
    var filePath = (application.getOSName().indexOf("Mac") > -1) 
                         ? "/user/lib/etc/myMacImage.png" 
                         : "C:/mywindowspath/public/myWinImage.png";
    return plugins.images.getImage(plugins.file.readFile(filePath)).getData();
}

```

Then you can use this form variable as a dataprovider for an image on your form (whithout using html).

Hope this helps,

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [July 8, 2009, 6:34am UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/7 "2009-07-08T06:34:20Z")

</div>

Hi Patrick,

thnkx for your example. This works fine for getting the image into a media field, but I’d still need to have it in a html area as I want to be able to type text as well.

Any idea how to take this last step?

---

<div class="post-metadata">

**Author:** ![Infop](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@Infop](https://forum.servoy.com/u/Infop)\
**Post date:** [July 8, 2009, 11:16am UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/8 "2009-07-08T11:16:14Z")

</div>

> sanneke:  
> Hi JuanMartin,
> 
> This is a sample of how you can send a email with a inline image
> 
> ```auto
> var attachment1 = plugins.mail.createBinaryAttachment('embeddedImage',plugins.file.readFile('c:/nok.jpg'));
> 
> ```

var msgText = ‘plain msgstyled msg ![]()’;  
var success = plugins.mail.sendMail(‘tsdsddd@gmail.com’, ‘John Cobb [from\_me@example.com](mailto:from_me@example.com)’, ‘subject’, msgText,null,‘unnamed@example.com’,[attachment1]);  
application.output(success)

> ```auto
> 
> ```

If I would like to send mail with a inline image from my servoy media library, then How can I do that?

```auto
var attachment1 = plugins.mail.createBinaryAttachment('embeddedImage', plugins.file.readFile('media:///myimage.png'));

```

Is not working…

Thanks.

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [July 8, 2009, 11:28am UTC](https://forum.servoy.com/t/jpg-or-html-on-email-body/10841/9 "2009-07-08T11:28:08Z")

</div>

To embedd images, more work is needed when the actual message is created. In the src tag of your image a reference to the relevant attachment has to be set and the header of the attachment has to be modified to not have it show up as an attachment. I don’t think you can do that with Servoy’s mail plugin. I know, however, that you can do that with our [MailPro plugin](http://www.servoy-plugins.de) ![:D]( "Very Happy") . There is a demo available, so you can check that out. If you have questions regarding this functionality, please contact us directly.
