SendGrid get email contents. C# - 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.

Related

How do I download the email I just sent using Graph API?

I am using GraphAPI for sending email. I have a situation where I need to Save a copy of the email sent. I can retrieve the Messages using graph api. How do I identify the email I just sent? When I use the SendEmail endpoint of the Graph api, I get a 200 OK response. How do I identify the email I just sent so I can download that email?
I have tried a number of solutions, adding custom Identifiers and filtering it but none of them worked.
I haven't tried this, but this approach seems it would work: https://learn.microsoft.com/en-us/graph/outlook-immutable-id#immutable-id-with-sending-mail.
Create the message as a draft with Prefer: IdType="ImmutableId" header
Save the returned id
Send the draft
Note that email sending is asynchronous so you might not be able to download the sent email right away. It could take some time to be available.

Show only attachment link in mailkit imap

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.

Forwarding/Redirecting email using asp.net C#

I am working on an asp.net job website. each company can post a vacancy and email address to contact to. I have found that competitors are copying the vacancies and email address from my site. How can I get rid of this ? What if i show a dummy email address on vacancy but when user copies this email address and sends email, it goes to actual vacancy email ? Is this possible using asp.net ?
Well, if your purpose is only to hide the mail id, why show it in the first place?
You could easily provide a mail link/button, and send an email using .net mail functions.
The mail address is available in code behind, but you don't write it to the page. If its not in the response, they can't copy it.
If the information is on your website, I don't think you can stop other people from copying the links.
You could add a button to a form where the user can add details to a set of fields which you then send on to the advertising company. This is how lots of job websites work.

user replying to email messages. How can you get data from users email?

I have difficulties implementing the following scenario.
Let's say you have a web site with ability to send and recieve messages between users.
User recieves an email with notification he has a new message on the software system (doesn't matter in what it is implemented). He can respond to this message by sending a reply via email or by logging into the site and replying to the 'message' using the site.
In case of the first approach if user simply replies to the email notification, how can you (as a developer) know what 'message' (ID) is the reply for?
I'm thinking the info would be stored in the MIME extensions. Are the MIME extensions transfered to the reply of the message? If yes than the solution could be to see the data of the original message notification for wich the user replyes to.
Any ideas? Thank you
The only “reliable” way would be to encode that information in the sender's address to which the user replies; you could also put it into subject or body of the message, and “hope” that the user doesn't tamper with it. There is an “in reply to (message-id)” header, but a lot of existing eMail clients don't set the header properly.
The usual mechanism is something like this: create an eMail alias prefix, and the append a message-id-code fragment to the end; for example, if this was for a purchase order confirmation, you could create an eMail alias handling addresses of the form po-*#example.com, where * is the unique message ID. Then, when you send your message out, you'd put the appropriate address in both the From: and Reply To: headers. EG:
From: "Purchase Order Confirmation (#1234)" <po-1234#example.com>
To: "John Doe" <jdoe#example.com>
Reply-To: "Purchase Order Confirmation (#1234)" <po-1234#example.com>
Subject: Confirm your order (#1234)
Depending upon your mail server, you should be able to define a “separator” character (typically - or +) that is used to split up the parts of the “local part” (left of #) of the eMail address; there is typically then another mechanism to map a prefix to a script to handle all addresses of a certain form. The script interface is often very much like CGI on the web, sending in some environment variables and piping the message itself in on the standard input. If your app is primarily web-based, you might find it more “comfortable” to gather the incoming eMail body, and POST it to a private (perhaps http://[::1]/getMailReply) handler. This may help you reuse existing code more readily.
We have set up a catch-all email address on our server - for example catch-all#myserver.com. When we send emails to users, we encode the message id and any other meta information we may need in the from address. You can obfuscate this or not, depending on what your needs are. So, for example, if the user has a new message in the system whose ID is 100, the from address of the email we send to the user would be something like reply-to-message-100#myserver.com. Make sure that whatever format you use for the from address would never generate a real email address on your mail server.
So, when the user responds to this message, it will get sent to the catch-all inbox you have set up. From here, you have a number of choices to make on how you process this email. In times past, we wrote a little scheduled service that would run every few minutes and check this inbox for new emails, process them as you like (insert into db, send more emails, whatever), and delete the message since you're done processing it. This is fragile since email clients all have slightly different ways of sending emails and it becomes difficult to parse the variety of client messages out there.
The second way we've done it is by integrating with http://postmarkapp.com/ - which has an incoming email api that should go public soon (we got in on the beta). You'd set everything up the same way only make your server's catch-all address forward to the postmark incoming address you'll set up with Postmark, and then Postmark does the message processing and calls a webhook you also set up to do what you like with the object received.
I highly recommend Postmark, but even the homespun method worked effectively, for the most part.
-M
Just a followup to the previous answer, Postmark Inbound is now live and public http://postmarkapp.com/inbound For each email sent to your specially formatted inbound email address, you'll receive a JSON formatted web hook API call with all the email components, headers, attachments sorted for you.

How to read any email account from a domain using C#?

I guess this is sort of two questions that are tied together.
Related questions have discussed how to read and parse email using pop3. I need to be able to do this, however, I want this to be able to work with any email address I need.
I am trying to allow users to submit content by emailing it to a unique email address, which will automatically know to which account the content should be associated.
Is there a good way to create these email addresses on the fly in C# and check these email accounts so for content submissions?
Alternatively is there a way to make a "wildcard" email account which gets all of the email sent to the domain and allows me to see what the to address was?
Most email servers will allow you to route all undeliverable email to a specific mailbox (though the details on how to do it will depend on the mail server). From there you should be able to get the address it was sent to from the To header of the message.
A much better method is to skip the inbox/POP-checking altogether and have your MTA (Message transfer agent) "send" incoming emails straight to your application.
Here's an example setup with PHP: http://www.evolt.org/incoming_mail_and_php
Alternatively is there a way to make a
"wildcard" email account which gets
all of the email sent to the domain
and allows me to see what the to
address was?
Yes its called catch all:
http://en.wikipedia.org/wiki/Catch-all
It depends on your domain host/who you are using to handle your email on the specifics of how to do it.

Categories

Resources