HTML email "opens" not being tracked - c#

Update
This question has gotten off on the wrong foot. Let me pose the question as follows:
Let's say I wanted to show my StackOverflow "flair" badge in the signature of an email in Outlook. Obviously, I would want the image to be refreshed whenever I reply to an email or forward the email. Now, assuming the I (and others) have decided to allow images to be downloaded from me (who in this case we'll call a "trusted source") then they would see my flair badge refreshed on subsequent loads. If I copy and paste this badge into a new email then the image will not refresh on subsequent page loads because Outlook has embedded the image and severed the link to original image.
I completely understand everyone's comments about spam but this question is more about Outlook VML and manipulation of it. If the answer is always and forever "spam! Off with his head!" then that's fine. I get it but it seems to me that there may be situations where someone may not want the default behavior of Outlook to modify an email that it has already accepted.
Original Questions
We have an internal mail system that dynamically generates and sends HTML emails. We have a web beacon generated by an HTTP handler. The system works as expected: users recieve emails and we track opens as the web beacon is called.
The problem occurs when someone takes that same email that they just received (and we just tracked) and copies & pastes the content (including the web beacon) into a new email in Outlook. Outlook embeds all images instead of maintaining the URL back to the web beacon.
Is there a way to generate an image through an HTTP handler such that the src of the image is maintained when pasted in Outlook?

No. There is not; That's how Outlook works.
Not only that, your use of "web beacons" is the primary reason that I and many others have our e-mail clients configured not to load external images at all except from trusted senders.

Related

jquery ajax call not working inside gmail [duplicate]

Is JavaScript supported in an email message?
http://en.wikipedia.org/wiki/Comparison_of_e-mail_clients
Old clients, such as Lotus Notes, Mozilla Thunderbird, Outlook Express, and Windows Live Mail all seem to have supported some sort of JavaScript execution. Nothing else does.
It seems like a bad idea security-wise, so I would expect this to be a feature that won't always be around, even in these clients.
Short answer
No
Descriptive answer
It depends. But the email is not guaranteed to behave in the way you want it to. Different email clients handle JS differently. Most of the newer email clients do not support any of it since it is potentially very dangerous to support script execution in a desktop application which contains so much of your personal info.
I had a use case where I needed to use JS in an email. I tried out on the web client of outlook and desktop client as well, and it turns out outlook just wipes out the script part of your HTML email. There might be some other email client which does support JS execution, but given that you cannot control the client where your email would be viewed in the client machine, it's not a good idea to embed any scripts in the HTML email.
Its advised to keep your HTML email as simple as possible, no JS, and the least CSS you can do with (because, again, different email clients have varying support for CSS as well) eg: outlook's web client was not even recognizing an HTML button tag in the email. I had to use an anchor tag and some CSS on top of it to mimic the display of a button.
Bottom Line - Don't rely on Javascript when working with HTML email content.
No, generally speaking email readers do not allow javascript.
Other answerers have suggested that the answer is "No."
On the other hand, an html attachment will probably get opened in an environment that runs Javascript.
EDIT: It was suggested that I haven't properly answered the question so here goes a more complete effort.
Summary: I would expect that many or most users receiving an html-formatted email containing embedded Javascript will see it run and have run tests to confirm that this is true in some environments. But Javascript WILL be blocked for some users.
The protocols (specifically RFC2854) explicitly address scripting (within the text/html message body type) with the statement that:
In addition, the introduction of scripting languages and
interactive capabilities in HTML 4.0 introduced a number of
security risks associated with the automatic execution of programs
written by the sender but interpreted by the recipient. User
agents executing such scripts or programs must be extremely careful
to insure that untrusted software is executed in a protected
environment.
So the protocols do support Javascript, but which user agents do?
My (ancient) email reader uses a table to specify which viewer software to use for each mimetype, diverting html content to my favorite web browser. Almost all current web browsers support Javascript (and some issue dire warnings when you try to turn it off!) Do modern email agents include internal html interpreters and, if so, is the javascript turned on or off? I've checked documentation on Thunderbird and find that javascript seems to be turned on by default but can be turned off: http://codeverge.com/mozilla.support.thunderbird/simple-html-tags-reference-docume/2030160
I have noticed that some (?many?) users now access their email from a browser directly (webmail is one such platform) rather than running separate email software. All such platforms which I have tested so far do run any Javascript embedded in the html of the email message. However some such environments, depending on user security settings, do not automatically fetch external links (Javascript or pictures or other) and so can only run external Javascript from a file which is included as an attachment to the message. The same would be true of any offline email reader on a device without a current internet connection.
The above applies to javascript embedded in the main message part of the email body. One can also have html explicitly given as an "attachment", which if saved and then opened would be displayed in a web browser, wherein Javascript is available with very high likelyhood. Therefore, one might included a second copy of the javascript enabled email as an html attachement with an alternative text/plain main body and/or tag in the main text/html directing the user to the attachment.
I've been thinking about this because some of my acquaintances insist on sending me "email greeting cards" which consist of a text message directing me to a link which I've found so unsatisfactory that I refuse to even consider loading it just on principle. I have written and sent email greeting cards with interactive graphics and music and even games using embedded javascript and been satisfied with the result.
Therefore, I maintain that the correct answer is "Yes" both on the grounds that the protocols specifically address scripting and on the grounds that all the email agents I personally use ran the Javascript in my test emails.
You aren't going to get executable JavaScript onto a server and into a mail client. But emails DO support links, you can always link to your content within an email.
For most mail clients, no.
No email client support javascript due to security concern
Try to send a mail with this HTML content
<!DOCTYPE html>
<html>
<body>
<button onclick="this.innerHTML=Date()">The time is?</button>
</body>
</html>
It may be, but mail clients won't read it & mail servers may reject it. So leave it out.
Javascript is not supported in emails.
You can view an email with JavaScript working with Windows Live Mail, but can't add JavaScript to a new email you wish to send.
JavaScript also works with saved .eml files.
Mozilla Thunderbird version 60.7.0 can't view or add JavaScript.
(If you save an eml file with Thunderbird, the code will work if file is then loaded with Live Mail)
You can send an email with JavaScript using PHP code.
Some email websites may support it, but the few I used don't. (AOL, uk2.net, GMail)
Short answer: No it is not supported in an email message
Long answer:
I have tested it with two email readers. Outlook (online) and OE Classic. As OE Classic is very outdated (I use it on windows 7), it does support JavaScript and I tested it with an alert button. However, the newer Outlook does not even support buttons, which showed up as plain text. So to conclude JavaScript is only enabled on some, usually older, email readers but not on new ones such as Outlook.

EWS: Retrieving more than just attachments from signed emails

I am trying to create a system that will intercept emails coming into various email addresses and catalogue them, along with all of their attachments. These attachments are all files that we need to load into another system. Currently, we are using Outlook Macros to drop all of the attachments to a directory and load them that way. Unfortunately, this method does not lend itself easily to tracking which emails had which attachments. If we want to ensure we are accounting for every document we have received, we need a more robust approach.
So, I am building an EWS-based Windows service. The idea is that it will subscribe to all of the email addresses that I want to manage. So, it will know about all new emails, catalogue them, and track the attachments. It works well for most emails, but emails sent securely need to be viewed by a person (as those emails require a log-in to a secure server somewhere to view the message and download attachments). But, digitally signed emails, I just wind up downloading an attachment named 'smime.p7m'. I found a post on this forum that shows me how to grab the attachments, but what about if the email body is digitally signed? Is there a way I could extract that, as well?
I decided to go with the MimeKit approach described here (it is not the accepted answer, but several of the answers deal with MimeKit, so I decided to check it out, and it looks promising).
My current approach is, if the email body was not digitally signed, then I can load that into my system directly from the base email. But, if it is digitally signed, then I need to grab it from the smime.p7m file, and that is where I am running into trouble. I have no problem using the examples to extract the attachments, though. Currently, I have no examples of a digitally signed email body. But, I would like to be proactive and find a solution before it does happen and a user asks why the email body is missing. Alternately, it would be equally helpful to know if this is not possible, and the only portion of an email that gets digitally signed would be the attachments (in which case, I can ignore this completely). That would actually be the best case scenario!
Generally, when a message is signed via S/MIME, the entire message (including the body and attachments) are signed.
Theoretically, it is possible for each individual component of the message to be signed individually, but that's not how most mail clients work (I don't know of any that do anything other than signing the entire message).
If you want to make sure to handle any scenario, just make sure to handle all MultipartSigned parts and/or ApplicationPkcs7Mime parts within the message and then you'll be sure to handle all scenarios (in other words, don't assume there is only ever 1 of those).

C# Sending gmail with uploading large file on Google drive attachment

I need to create a program in c# that can upload to google drive and attach it to email(gmail) and send it to recipients. The file is more than 50mb that is why we need google drive to send. Is there a google api available to do those task all in one? Is that possible? I have been reading solutions here but mostly uploading file to google drive and sending email are separate solutions and I am having a hard time combining those two task. Can somebody direct me if there is a proper code or api to do those task.
The program will provide the following information
sender email: username
sender email: password
upload directory and file
recipient or email receiver
#Mandz Yeah, I'm not sure if there is an automatic way of attaching the file to the Gmail's e-mail, however, the way Gmail handles links is quite interesting:
As you can see, it attaches the link to the attachment, making it in some way automatic.
Here's the link to the GitHub repository:
link
I've decided to make it GUI using WPF and MVVM pattern (using Caliburn.Micro). Hopefully, it won't be too difficult to run the sample app on your end.
Here are the steps that you need to do in order to run the app:
Have a Google account.
Login into https://console.developers.google.com/ (It is a platform where you handle all your tokens etc.)
Create a new project - top left, click on Select a project, new window should appear, click on New Project, name it whatever you want, when that's done, click on Navigation menu (top left), APIs & Services -> Library, Search for Google Drive and Gmail API, enable them both. Then go to Credentials (In APIs & Services), click Create credentials, choose OAuth client ID, you might need to configure consent screen (but I think it's pretty easy, you have to choose either Internal or External and provide the Application Name), in Create OAuth client ID, choose Other, name it whatever you want, Click Ok on the new window, then Download JSON on Credentials Page (on the right), place the file in the same dictionary where the .exe app is. Then create another credential for Gmail token (the same way as above I believe). Place it again in the same dictionary where the .exe app is.
To run the app, you will need .NET Core 3.1 https://dotnet.microsoft.com/download (or just new version of Visual Studio)
Build the app, Click the Choose button to select a file, then Click Upload button.
If the tokens are in the same dictionary, a new website should launch and ask you to log in to an appropriate account (I would choose the same Gmail account where you created these tokens) then if you give access to this app, agree to that. When that's done, a token folder should appear in the same dictionary as the .exe file. The reason why the token folder is created is so you won't have to repeat the 6th step.
A downloadable link should appear, copy it and paste in the Text field in the E-Mail tab.
Type the E-mail address (I would suggest your alt account or something so you can just test it).
A subject field can be empty.
Click Send-Email (now just redo the 6th step)
Some side notes:
I had to create two tokens, for Drive and Gmail APIs, I dunno if it's the quickest way of doing this, I tried to just use 1 token but it didn't want to work.
MainView.xaml is just the things that you see, so it doesn't really matter in this case.
MainViewModel.cs is the file where all the important things for you are.
I would look at UploadFileAsync method, it does upload to the root folder (the main folder of Google Drive), then puts the file to the public so anyone can access the file and download it, then gets the public link to the file.
SendEmail method sends the E-Mail.
I put these methods asynchronous so the app won't just freeze (hopefully it won't be a problem for you).
The code is not perfect but I think it will do as learning material.
Feel free to post any questions about it, below. Good luck.
Edit: If you want link like this instead of full link, you change in string plainText to "<p>test<p>"

What is the best way to display an exchange mail message on an ASP.net web page?

I have a list of actions happend on an item listed on an ASP.net website. These actions are logged in a simple sql table linked to the item.
i.e.:
[2013-11-04 18:00]: Problem solved
[2013-11-04 18:00]: Called User
[2013-11-04 14:00]: Mail Received
For this, I will have to query the support mailbox for new mail messages. When a new message is received, a 'mail received' action is created. The 'mail recieved' entry should be clickable so the support user can see the contents of this message.
Question: How do I show this message to the support user?
Using Exchange Webservices Managed API 2.0 I can find this message and his body but the message body can have inline images and other layouts.
Options:
Show the message on the web page try to render the mail message the best way I can.
-> Are there any free plugins that do this? Something like this but that can be used in a web page?
Use Outlook to display this email message.
1&2 combined.. show a preview text-only message and click to see the whole message using outlook.
Since the support user will have Outlook 2010 or higher installed on his machine, the 3th option seems a logical choice but how can I display this message in outlook?
#{
HttpContext.Current.Response.AddHeader("Content-disposition", "inline;filename=message.msg");
HttpContext.Current.Response.ContentType = "application/vnd.ms-outlook";
}
#(new HtmlString(ViewBag.Body))
Obviously doesn't work.. a .msg file seems binary. Do I need an API for this?
But even when this works I will have these problems:
Every time you open a message you will have to click 'Open' to view this message.
-> Can I prevent this in modern browsers (primarily IE10 & IE11)?
-> Or are there 'inline outlook viewers' available?
When this support user answers this message using his outlook, this message will be sent 'from' his account. There would be no trace of this sent message!
-> Can anyone think of a way around this?
We are using an on-premise Exchange 2010 SP3 server that should be migrated to Exchange Online some time next year. Application is running on ASP.NET 4.5 using MVC 5.0 framework.
It could be solution to use this API to download messages as .msg file directly from Exchange server
Tinker with the different body types and retrieval methods. Info here:
http://msdn.microsoft.com/en-us/library/ee217562(v=exchg.80).aspx
See if any of them return something that's relatively easy to display, whether that be parsing the HTML body or showing the RTF body in the browser. I haven't mucked with this much and don't have an Exchange server handy or I'd check myself. If Exchange doesn't chew up the HTML when the message is send, you may be able to parse out the src="cid:contentIdOfAttachment" and replace it with a proper link to the attachment for display in the browser, but Exchange can do funny things to HTML and CSS.
And for clarification, by "support user", do you mean a support employee (ie, tech support) or someone who is receiving support and checking on the status of their ticket? If the message is to be shown and/or replied to in Outlook, would this person be accessing a single support mailbox (perhaps a public folder) or would the message be forwarded/copied to the person's individual mailbox?
If I'm getting this right, you'll be copying it to an individual mailbox, and from there it's "outside" the system, so the reply goes straight to the end user and skips the central support mailbox. You might be able to circumvent this by altering the message before it is sent/downloaded by changing the "from" to the central support mailbox. When the support user responds, it goes back to the central support mailbox, where you can have a secondary sync action (or even the same one that's fetching incoming mail) process it, change the to/from to send to the intended recipient from the central support mailbox, and send it off by using UpdateItems and saving it to the Sent folder. It's not pretty, but it should be possible. That's just off the top of my head, though, so there could easily be a better solution. And I'm operating on a few assumptions about the system you're working in, so maybe I have things a bit wrong.

Capture email sent with outlook from browser

I want to be able to capture a email that gets sent via outlook and initiated from a browser mailto link so that I can save a copy back to my web application.
I can get buy with c#, I am currently building a web application using c# but would ideally like it to be possible to do from a php application without needing to rely on a specific web browser.
So far it seems that my best option will be to build an add-in for outlook that can detect the relevant flag and save a copy of the email once sent back to the application via a webservice connection.
I don't have a great deal of experience dealing with Office add-ins and am interested to know if I can pass custom information through the mailto link and then read it using the add-in when new message is started.
I also seem to have an issue where I don't have access to certain information while the email is being composed and don't have a reliable way to match that particular in-composition email to the email that gets saved in outbox then moved to inbox.
I am working with Visual Studio 2010 and Office 2010 at the moment.
You can't do this normally because when you supply a mailto link you're actually requesting the default mail program on the user's computer to send the mail. Because you don't know (and shouldn't be willing to know) which program this is you have no control over the mail sent.
One solution would be to have a special page in you web application in which your user can compose it's email. After composing you could supply this format to the SMTP server for delivery and you could store it wherever in your webapp you like. The point here is that you want to stay in control and having a mailto link will send the control over sending an email to a different program.

Categories