create email with embedded image gmail api - c#

I am able to create an email draft using the gmail api. I'm also able to create a draft with an embedded image if the image is a real file.
The next step I want to reach is to create a draft with an embedded image where the image is just a screenshot on my clipboard. By creating the draft my html img tag looks something like
" img width="593" height="363" src="data:image/jpg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAMCAgMCAgMDAwM......"
but in gmail this part of my draft is empty.
Does someone know any solutions for this ?
Thanks a lot !

Related

Mime - Where can I find where images in emails are stored?

I'm currently sending reply emails via SMTP using SendGrid to emails I receive. I save the emails I get as .msg and load them as MimeMessage. I add some text as a reply but if the emails have images, the images don't seem to get passed through and I'm not sure exactly where they are. My goal is to send the reply emails with images being retained as currently they show as blank boxes in Outlook saying 'The linked image cannot be displayed. The file may have been moved, renamed, or deleted'.
From my research, I am seeing that images are passed in through attachments and the body of the email show the image as cid:image001.png... . I can't find where the actual images are stored though. When I look into the MimeMessage, attachment is null (unless I attach a file to the email, that file will show but not images within a body of email)
Does anyone have any tips for where to look for the image(s) of emails?
Update: I found the image stored in Body Parts. Will figure out how to pass that one to the reply next.

Is it possible to send an attachment in Outlook as a URL

I have an Outlook addin that handles attachments by sending them to our server and then embedding a link into the body of the email containing the URL to the uploaded attachment.
This works but it is not 100% satisfactory because the URLs can get broken depending in the email client and the sender will not see their attachments listed at the top of there email where they are use to seeing them.
Ideally what I would like to do is exactly what is being done for OneDrive.
Currently if I add an attachment and provide a URL as the source it will download the file and send it as a normal attachment which is the exact opposite of what I want. I have noticed that if it fails to download the file it will then just send the URL as an attachment which is what I want. But sending broken URLs is not very useful.
Using
Outlook.MailItem.Attachments.Add("https://myserver.com/somefile", 7, 1, "MyAttachment")
If I set the attachment type to '7' which is what is used for OneDrive attachments I can get it to send the URL but it will first complain about not being able to set some access rights and if the sender clicks OK to continue anyway the attachment will appear to the sender and the receiver as residing on OneDrive which it is not, but clicking the URL will download the file from my server as I want.
My question is: Is it possible to send a none OneDrive URL as an attachment?
(I expect the answer is no, but I am hoping some Outlook guru out there may know some trick to do this.)
My other alternative it to wrap my URLs in an small html file that is then sent as a normal attachment and when opened will provide the link to the actual file.

sending email with images

I have a WinForms application where a user can configure email templates that will later get mail merged with client data from the database and then sent via SMTP.
I have everything working fine, but the issue comes when the user saves images inside the template body. I'm using a DevExpress RichEdit control to allow the users to create this email body, and that control converts it to HTML that I use to send. When images are there, it uses data-uri to embed the image directly into the HTML.
The problem now comes when I send the email in this way using data-uri images, not all clients render it properly. I just tested it in Outlook, and it doesn't seem to work. I know some web based email clients will work, but I need this to work all the time, at least for the widely used email clients.
I'm wondering if others have solved this problem and what might be the best solution here? I suppose I could send the images as attachments and then reference the attachment, although I'm not sure if this is a best practice. The other alternative though is to host each image on a server somewhere, then create a service which would have to store the images (like in a DB), and provide a way to query this image over the web using an ID. Then my emails would use an img src=site/getImg?imgID=xxx type thing. However, this seems like a lot of work to do what I want to accomplish and I'm hoping I could avoid it with something easier.
Thanks in advance for any advice!!
Adding images as attachments will work, but has the downside of a larger payload and higher bandwidth utilization both for you and for your recipients. The code for adding attachments in .net is pretty simple:
var message = new MailMessage();
foreach (string path in attachmentPaths)
{
if (File.Exists(path))
{
message.Attachments.Add(new Attachment(path));
}
}
On the other hand, referencing images stored on the web somewhere reduces the size of your emails and also opens up the possibility of gathering tracking data on clients that request images. Of course, most email clients will first ask the user whether they want to download images, so your tracking will only be rough.
you should be try save the images in the local disk , and the next include the who Embedded images.
// Add image attachment from local disk
Attachment oAttachment = oMail.AddAttachment( "d:\\test.gif" );
// Specifies the attachment as an embedded image
// contentid can be any string.
string contentID = "test001#host";
oAttachment.ContentID = contentID;
oMail.HtmlBody = "<html><body>this is a <img src=\"cid:"
+ contentID + "\"> embedded image.</body></html>";
Sorry for not explain, I speak only a little in english

How to get image from url using c# / javascript

I am using file picker apis , i can easily upload my files to there server and they give me a unique url in return . When it comes to again fetch that file its creating a problem to me .
You can tell me how to get back file using that url by using filepicker api .
You can tell me how to use that url and get image , by using c#
When i upload a picture to filepicker.io they return me a json object like following
[{"url":"https://www.filepicker.io/api/file/kIrtNvQRta7GxlFVfiP2","filename":"brazil.jpg","mimetype":"image/jpeg","size":2660,"key":"ZML3OjrFTVyV4waBzRIT_brazil.jpg","isWriteable":true}]
So how to get back that image file using c# / Filepicket javascript api
Edit
In my site user will come and upload many photos , and every link to that photo will be stored in database . Now if user want to see his uploaded pictures then i want to fetch them again from server by url . So give your solutions acc. to this scenario .
Thanks in advance
You could put the picture in a PictureBox first using: PictureBox.Load(string);
After the PictureBox is filled with the image from the url, you can decide what to do next like: saving etc.
PictureBox.Load

How to programatically upload/post an image to an image hosting website without a browser?

I want to write a simple utility to upload images to various free image hosting websites like TinyPic or Imageshack via a right-click context menu for the file.
How can I do this using .NET? I've seen some linux scripts that use cURL to post images to these website but I'm not sure how I could create the post request, complete with an image in C#?
Can someone point me in the right direction?
EDIT:
I've found a pretty good resource. Cropper, a free screenshot tool written in .net, has a lot of open-source plugins. One of them is a SendToTinyPic.. complete with source. Link here:
http://www.codeplex.com/cropperplugins
The FlickrNet API makes this extremely easy for working with Flickr from .NET. You have to have a Flickr account as well as an API key and shared secret. Once you have what you need, working with the API is very simple:
// http://www.flickr.com/services/api/misc.api_keys.html
string flickrApiKey = "<api key>";
string flickrApiSharedSecret = "<shared secret>";
string flickrAuthenticationToken = "<authentication token>";
Flickr flickr = new Flickr( flickrApiKey, flickrApiSharedSecret );
flickr.AuthToken = flickrAuthenticationToken;
foreach ( FileInfo image in new FileInfo[] {
new FileInfo( #"C:\image1.jpg" ),
new FileInfo( #"C:\image2.jpg" ) } )
{
string photoId = flickr.UploadPicture(
image.FullName, image.Name, image.Name, "tag1, tag2" );
}
Use HttpWebRequest.
Using this class, you can POST data to a remote HTTP address, just set the mime/type to multi-part/form encoded, and post the binary data from the image with the request.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(VS.71).aspx
For ImageShack, take a look to this Application.
TinyPic.com doesn't have an API as far as I know, but the Cropper SendToTinyPic Plugin tries to upload using "Screen scraping". The official version of the plugin doesn't work right now, but I put together a patch using the same approach, and submitted it to the cropperplugins project. It's just one source module that changed. Anyone can download the plugins project, and then drop in my patch and it should work.
With the patch, it's PritScrn or Alt-PrntScrn will save the image and upload to tinypic, and stuff the URL of the raw image on your clipboard. All in 2 seconds. easy.
If you don't want the actual tool, you can still look at the source code of my patch to see how to POST a page with form-data and a file upload. No direct link. See http://cropperplugins.codeplex.com/SourceControl/PatchList.aspx and look for #3239.
This example image was produced and then auto-uploaded to tinypic.com with the Alt-PrtScrn key-combo.
To embed it here, I just had to ctrl-V because the URL is stored on the clipboard.

Categories