I am having an issue testing alternate views while sending HTML E-Mails. I am creating sending the mail message as plain text, but I include an HTML alternate view. I have tried using several e-mail clients, but I have been unable to see the plain text version. My main concern is that someone who does use a plain text only client won't see it correctly. See below for code:
MailMessage message = new MailMessage();
message.To.Add("email");
message.From = new MailAddress("fromaddress");
message.Subject = "subject"
//Plain text version of e-mail
message.Body = _formattedPlainText;
message.IsBodyHtml = false;
AlternateView htmlView = CreateHTMLView();
message.AlternateViews.Add(htmlView);
//message.AlternateViews.Add(plainTextView);
smtp.Send(message);
private AlternateView CreateHTMLView()
{
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(_formattedHTML, null, System.Net.Mime.MediaTypeNames.Text.Html);
//Code for adding embedded images...
return htmlView;
}
Is there reason to believe the plain text version isn't being received or are there any clients you know that definitely can only receive plain text e-mails?
Thanks in advance
UPDATE:
You can force plain text in GMAIL by pressing the options arrow and selecting the option "Message Text Garbled?"
Is there reason to believe the plain text version isn't being received
or are there any clients you know that definitely can only receive
plain text e-mails?
No, and PINE.
You could use the mail command in any *nix OS to read email. It will only display email in text format.
UPDATE
A guy here, claims that GMAIL ONLY displays emails in plain text if given the option. I find that an awkward default choice from Google if that's still the case.
Through some experimentation I have had best results this way:
Set up two alternate views, one HTML and one plain text.
Then, leave the MailMessage.Body alone (default/undefined) and
leave the MailMessage.IsBodyHtml at default. My code segment:
myMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(HtmlMessage, new System.Net.Mime.ContentType("text/html")));
myMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(TextMessage, new System.Net.Mime.ContentType("text/plain")));
// myMessage.Body = HtmlMessage;
// myMessage.IsBodyHtml = true;
myClient.UseDefaultCredentials = false;
NetworkCredential credentials = new NetworkCredential("xxxx","xxxxx");
myClient.Credentials = credentials;
myClient.DeliveryMethod = SmtpDeliveryMethod.Network;
I have tested this with messages sent to Windows Outlook clients and to Mac users, and it seems to work just fine. The email client software chooses the view. I still need to test how this works for clients such as webmail apps. Your mileage may vary.
Bob
Related
I have an application that requires a user confirm their email upon registering, so I've created some functionality to send the user an email, with a link, where they can click on the link and then confirm their email.
In order to do this I'm using both MailMessage and SmtpClient classes to send the email.
Currently, my code is thus:
public ActionResult Send() {
MailMessage email = new MailMessage {
Subject = "Confirm Email",
Body = "<a href='http://www.google.com'>Google</a>",
IsBodyHtml = true
};
SmtpClient smtp = new SmtpClient();
smtp.Send(email);
return RedirectToAction("Index", "Email");
}
Now upon researching I found that the IsBodyHtml flag will help if I'm trying to send an email that has HTML contained within, although upon testing, the emails I'm receiving are not formatting anchor tags properly.
Any idea what I may be doing wrong, or how differently I can go about formatting my message body?
Thanks!
So, I made a goof here. Seems that the messages I was trying to send myself were going to Outlook's Junk Mail folder, which strips out the href value and displays it in the e-mail.
If I right click on the email and select Display HTML then the link displays as expected.
Oops!
Introdution
I am currently working a system develop with C#.
The system is about request approval.
When a request made, system will send email to user ask for response.
User's response will as simple as approve, reject or request update.
Question/Problem
Is it possible to have a button (approve or reject) in email content which allow user to response to system with only one click but without open browser?
Or, Is it possible to create button in email content which enable user to click to create new email with pre-set subject and recipient like following:
subject: request id - 123 - action - approve
to: response#system.com
as response email for user to send.
Then system can then recognize the email received and perform required back-end process.
Research Done
Research 1
What I currently found was outlook appointment email.
it done like second solution create new email with content for user send a response.
But, it only have options accept, decline and tentative.
And, I am not sure is blackberry support it like outlook.
The following is the blog found to create appointment email:
http://chuckdotnet.blogspot.my/2007/10/send-outlook-meeting-requests-with.html
Research 2
The following website teach you how to create hyperlink in email content which can create new email with pre-populate subject, body, and recipient
https://community.articulate.com/discussions/building-better-courses/hyperlink-to-create-an-already-written-email
However, No test had perform in blackberry yet.
Appreciate for any suggestion from you guys and I willing to try.
Is it possible to sent an email with button which can click to create
email with some pre-set content?
Yes, this is possible, see the System.Net.Mail code in the .NET framework.
https://msdn.microsoft.com/en-us/library/system.net.mail(v=vs.110).aspx
You can also see this StackOverflow question about how this is used.
Send e-mail via SMTP using C#
MailMessage mail = new MailMessage("you#yourcompany.com", "user#hotmail.com");
SmtpClient client = new SmtpClient();
client.Port = 25;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtp.google.com";
mail.Subject = "this is a test email.";
mail.Body = "this is my test email body";
client.Send(mail);
Finally, your code should fire a serverside post on button click to have the server take care of sending the email. If data needs to be posted to the server, you may want to consider putting this data in a form input, which will post to your controller. You can then take that data and build the email with the example I provided in the links.
I want to allow the user of the handheld device software I'm working on to send me email (the contents of a log file, which will have exception data and other info for debugging).
How can I do that? All the user should have to do, on seeing the contents of the log file (which I display to them on-demand in a form), is to mash a "send this" button. The contents of the log file (which can be read from the Textbox in which they are displaying) can be the body of the email message (rather than an attachment), with the subject line being something like "{user name} log contents"
If I have to prompt the user for their email address, that's probably okay, but I would prefer to use one of our email addresses as the sender, so that it's seen as being both from us and to us (probably two different accounts, though).
One way would to use the SDF and the OpenNETCF.Net.Mail namespace objects. It works like the System.Net.Mail objects, so sending an email would look something like this:
var message = new MailMessage();
message.From = new MailAddress("sender#mydomain.com");
message.To.Add(new MailAddress("recipient#domain.com"));
message.Subject = "Hello World";
message.Body = "This is my message body";
var client = new SmtpClient();
client.Host = "smtp.myserver.com";
client.Credentials = new SmtpCredential("myusername", "mypassword", "mydomain");
client.Send(message);
I need to send a html file(which contains a iframe) inside a email body.The html file is working fine in a browser and playing a video.But when i send it inside email body,iframe tag is not getting interpreted so does not show in the body.
This is html file.
<b>Aman</b>
<iframe height="390" frameborder="0" width="640"
src="http://www.youtube.com/embed/Sf5T5KjMpJU?wmode=transparent"
title="YouTube video player"></iframe>
Email body only displaying a "Aman" in bold.This is C# code.
StreamReader reader = File.OpenText("C:\\Users\\Girish\\Desktop\\amrit\\Jeff_Project\\indeex.html");
string getemail = textbox_email.Text;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
message.To.Add(getemail);
message.Subject = "Hello";
message.From = new System.Net.Mail.MailAddress("sendingemail");
//message.Body = "This is message body";
message.IsBodyHtml = true;
message.Body = reader.ReadToEnd();
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.Credentials = new System.Net.NetworkCredential("sendingemail", "password");
smtp.EnableSsl = true;
smtp.Send(message);
Response.Write("Sent");
Why iframe is not being interpret?Am i missing anything?
Please help and provide solutions.
Thanks in advance.
emails doesn't support objects tags inside them.
read this
I even tried to send myself a youtube video from youtube, and even them not embedding the video in side the email body.
Instead of trying to embed the video as a link (like youtube does)
most email clients only support very basic html. to be safest, we have to generate our newsletter content using table layouts and just simple a, span, and img tags for content.
if you try to use divs for layouts, outlook clients will barf when trying to render them. this is because outlook uses microsoft word to render html documents. as a general rule, we always test layouts in microsoft outlook because that client tends to be the lowest common denominator. if it looks good in outlook, it'll generally look good everywhere else.
I am using MailMessage in C# to send out a HTML email. The code I am using is as follows
MailMessage msg = new MailMessage();
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<B>Test Message</B>", null, "text/html");
msg.AlternateViews.Add(htmlView);
I use the Alternate view because I need to attach files and embed images in the email body. When I send out the email to my gmail account, I see the HTML tags displayed in the inbox. Clicking on the message to view the actual email gets rid of the tags. How do I ensure that the tags do not display in the inbox?
Thanks
I solved the issue. I am posting the solution as an answer to my own question to help others who may run into the same issue
My code had
MailMessage msg = new MailMessage();
msg.Body = "<B>Test Message</B>";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<B>Test Message</B>", null, "text/html");
msg.AlternateViews.Add(htmlView);
The second line of code needed to be removed since I was specifying both a body and an alternate view which was causing problems.
Does the message itself need to be marked around isBodyHtml ?
msg.IsBodyHtml = true;