Show only attachment link in mailkit imap - c#

I just want to display the links of attachments to download in mail body without downloading the attachment initially. coz i don't want to download and save the attachments on my server everytime.
when users clicks the link, then I want to download that particular attachment(s) from gmail server ("https://mail-attachment.googleusercontent.com/attachment/u/1/?xxxx-xxxx")
is there is anyway to do this?

MailKit does not provide any way of doing this because it's not something that IMAP supports.
That said, it might be possible to figure out how to construct the URL based on the properties of the MIME attachment.
Based on examining the Download link in one of my own emails, it looks like Google uses their X-Attachment-Id header value to construct the realattid portion of the url. They probably have other variables as well, but it's hard to know exactly where the other values come from.
The attid value in the download url appears to be a positional value of the MIME attachment in the tree, similar to MailKit's BodyPart.PartSpecifier string.
Instead of trying to recreate GMail's download link, you could always use MailKit's ImapFolder.GetBodyPart() API to download individual MIME parts when the user requests them.
In order to take advantage of this API, you'll need to call ImapFolder.Fetch() with MessageSummaryItems.BodyStructure.
You can take a look at https://github.com/jstedfast/MailKit/blob/master/samples/ImapClientDemo/ImapClientDemo/MainWindow.cs to see how to use the MessageSummary.Bodyproperty that you get back from the Fetch request.

Related

SendGrid get email contents. C#

I am using send grid from my MVC application but I would like to get the HTML of the email sent via the system so that I can store a record of it (as its sent) in a database for record. Does anyone know how this could be done. Thanks.
You can use the BCC (SMTPAPI or WebAPI) functionality to copy an email to SendGrid's Inbound Parse. Then, you can grab the content, headers, etc and save to your database.
Just a heads up, this will use one credit for the send and one credit for the BCC.

How do I send output of ASP.NET webforms site to a string/email ?

There is a site for sales where the end user prints out the details for the customer and that already contains all the information/HTML/ASPX page.
They want me to now send this HTML to the user as an EMAIL...
So rather than recreate each piece bit by bit.. is there someway to tell the server when it is done rendering the page to send the output to a string perhaps? Then I could have a function that takes that HTML in the string and creates an email with it.?
Don't send the exact HTML of your page as an email, as the results likely won't be good when viewing in their email client. Instead, custom generate the body of your email, and send it using the functionality in the System.Net.Mail namespace. Probably start with MailMessage and SmtpClient.
A page is usually formatted for a large browser window and contains much extra stuff like JavaScript and navigation elements. And it often refers to external CSS files for formatting. Consider that this wouldn't look very good when viewed in an email client. So yes, better to hand code or at least selectively get the HTML of your relevant Controls and send that rather than sending the HTML for the entire page.

Download PDF File From DB to Local Server for Download

I am trying to figure out how to get a file that I have stored in my Database, onto the filesystem. I have looked everywhere, but all I can find is like for images pulling them out and serving them via Response. Can anyone point me in the direction of a tutorial or provide me with some input on which way to go?
From the perspective of serving the file through the web, the process is exactly the same for images as it is for any file type. The only difference would be the content type in the response header. (For a PDF, it would be application/pdf.)
Understand that over HTTP there is absolutely no concept of "files." All you have are requests and responses, each of which has headers and data. Whether it's an image, a PDF, a web page, anything... the structure of the response being delivered to the client (browser) is exactly the same. Headers tell the browser what kind of data it is and various other meta-details about it, and the data is just the raw data of the "file" being sent. The browser can choose what to do with the data.
In the case of web pages, the browser generally just renders it. In the case of other or unknown content types, the browser generally prompts the user to save it as a file. (Note that a file name can also be suggested in the header of the response.)
Edit: In response to your comment on #Pete M's answer...
The process is still very similar. "Files" as email attachments work in much the same way as "files" over HTTP. Essentially, all you need is the data stream and the content type. When building the MailMessage object, take a look at the Attachment object. As you pull your PDF file from the database (just like when pulling images from the database to serve to a browser client), set the data stream to the ContentStream on the attachment object. Then also set the ContentType (again, application/pdf) and the Name on the attachment object and you should be able to send it as part of the MailMessage.
You may need to set more options on the Attachment as well. Testing will indicate how explicit you need to be with things like encoding. If you can share some code as you attempt this, we can help you with that code.
It's no different than writing out any other kind of file. If you find a good "read/write text file" tutorial it's going to be the exact same process, you'll just get your initial stream from the database.
Can I ask why you are doing this? If it's for caching so you can return it to users who ask for it I would consider other options first. Requiring a dip into disk will often cause a bottle neck in performance.

How do I use the Windows Mail Protocols? (C#?)

Well, for my program(s) I'd like to let the user send me an e-mail with any errors. Instead of relying on a forsaken SMTP server, I decided to let the user use his very own e-mail client to send an e-mail to a specified address.
So what I need is:
A sender (should not be changeable) (example: mysupportemail#gmail.com)
An attached file (should not be changeable) (example: "C:\a file.log")
(Optional) A body (changeable)
I hope it is possible!
You can use the mailto command for this. See http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx for more information. Some mail clients support attachments on this. See the comments of the MSDN page for some information on this.
The mailto protocol has limitations, such as not being able to specify an attachment (some mail clients support it, but it's not in the official protocol). Your best option is probably to use the MAPISendMail function to let MAPI do the hard work. See this article for details:
Sending files via the default e-mail client
I used this technique in the past, it seems to work perfectly.
Using mailto directly from you application cause potential problems. If you have specified mail account for receive e-mails you can be sure, that someone will use it somehow to sent you spam or thousands unwanted emails. In our company we struggled with this problem many times - at last, we decided to allow our customers to report problems in any other way - web page form.
Now, when customer click 'report problem' this option displays a form for reporting bugs in default web browser. Opened link include some additional information which causing partial fill of the form opened by customer. Now, we have an intermediate layer and absolute control on server side who report problem (ip) and we can limit reporting for specified users. Next advantage of these solution is that you can forward emails to different departments depending on what form fields are marked/filled with.
Well, I have found the perfect solution!
For those who want to see it...
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/a75533eb-131b-4ff3-a3b2-b6df87c25cc8
http://www.eggheadcafe.com/community/aspnet/2/10019665/email-through-gmail-in-c.aspx

Getting a file into Request.Files

I have a device that uses a custom scripting language. This language provides the capability to set http request headers then perform a post to a URL. The server that the device communicates with is running .net, and I would like the handler on the server to retrieve data from the device by simply pulling it from the Request.Files[] collection. To do this, does the device need to support multipart posting or is it possible for the uploaded content to show up in the Files collection by simply setting a number of headers then sending the data?
I'm not a linux guy, but I did a search and I found this. Does it help at all? (see section 4.3)
http://curl.haxx.se/docs/httpscripting.html
If you mean that at the server end you want the file(s) to be readable via HttpRequest.Files, then I believe so.
I think the format that this expects is based on the File Upload RFC and therefore if you follow the standard procedure for submitting a file upload then it'll work.
As to how you go about formatting the request from your device - I'm afraid I can't help on that one. Assuming you can format an Http Post, writing any headers you need and then formatting the Post body with the file content, it'll work, though.
In order for .Net to be able to read a file posted to a header it must be in the multipart posting format. Otherwise it will just be text noise in the header and .Net won't know what to do with it.

Categories

Resources