Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
I am sending an email, passing a string body(returning string via partial view), the string contains anchor or img tags. After receiving mails, i get to know that Anchor tags href attribute is not present , similarly img tag's src attribute is not present.
How can i made them available?
Here is the content which i would like to send as an email.



HTML
Here is the content....



<html>
<head>
    <title>Preview</title>
</head>
<body>
    <div style="font-family:'Times New Roman'; font-size:20px;">
        Hello <strong>&lt;label id="lblusername"&gt;User Name&lt;/label&gt;</strong>  &lt;br /&gt;&lt;br /&gt; As a loyal Bday Rewards member,
        you will sometimes receive special offers from some of our participating businesses! &lt;br /&gt;
        Today, <strong>
SUMIT    </strong>, wants you to hook you up with a special deal. This can be used anytime (not just around your Birthday!).&lt;br /&gt;&lt;br /&gt;
    The time to use them is limited, so please check it out and get to <strong>
SUMIT</strong> to take advantage of this special offer!&lt;br /&gt;
    Thanks again for being a Bday Rewards member and enjoy using your special offer!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;
&lt;div&gt;
    &lt;div class="pi-row"&gt;
                    &lt;div class="pi-gallery-item pi-padding-bottom-40" style="max-width:290px;display:inline-block;margin:10px;vertical-align:top;border:solid 1px;height:600px"&gt;
                        &lt;div class="pi-img-w pi-img-round-corners pi" style="vertical-align:middle"&gt;
                            <center>
                                &lt;br /&gt;
                             
                                <a target="_blank" href="http://localhost:59120/Business/BusinessProfile/?eagh=34353989879834435hkjhkjiu345793439jkhkj98375834534hjkhksdfsuhiuiiiusdihsif34895873954878&amp;uid=23382&amp;bid=6068">
                                    &lt;img src="http://localhost:59120/Content/Upload/Sumit+Photo.jpg" alt="" style="max-height:150px;width:auto;" /&gt;
                                </a>
                            </center>
                        &lt;/div&gt;

                        
                        <a target="_blank" href="http://localhost:59120/Business/BusinessProfile/?eagh=34353989879834435hkjhkjiu345793439jkhkj98375834534hjkhksdfsuhiuiiiusdihsif34895873954878&amp;uid=23382&amp;bid=6068" class="/Deal/Index/">
                            <h4 style="word-wrap: break-word;">
                                <strong>
                                    <center>
                                        Dominos
                                    </center>
                                </strong>
                            </h4>                        </a>
                            <center>
                                &lt;div id="redeemButton" style="background-color:#0dc0c0;WIDTH:80%;height:60%;border:1px thin #000;border-radius:5px;"&gt;
                                    &lt;br /&gt;<h3>                                              <a style="color:#FFF" target="_blank" href="http://localhost:59120/Business/BusinessProfile/?eagh=34353989879834435hkjhkjiu345793439jkhkj98375834534hjkhksdfsuhiuiiiusdihsif34895873954878&amp;uid=23382&amp;bid=6068">
                                                  CLICK HERE TO REDEEM NOW
                                              </a>
                                    </h3>                                    &lt;br /&gt;
                                &lt;/div&gt;
                                &lt;br /&gt;
                                <h5 style="text-transform:none;padding:0px 5px 0px 5px;">ghjgh</h5>                                brought to you by &lt;br /&gt;
                                <strong>    SUMIT </strong>
                            </center>
                            
                                &lt;input id="12118" name="23382" type="hidden" style="visibility:hidden" /&gt;
                           
                    &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


What I have tried:

I have tried setting IsBodyHTML = true
Posted
Updated 12-Jun-16 5:33am
v2
Comments
Dave Kreskowiak 12-Jun-16 9:28am    
Without seeing the rest of the code that generates the email it's impossible to tell you what you're doing wrong.

It's entirely possible you're not doing anything wrong, depending on if the email client can handle HTML emails. Just about all do, but there are still machines out there running Windows 95, so I'm not going to rule this out.
Sumit Bhargav 12-Jun-16 9:42am    
Hey there,
Thanks for responding, here is the code as follows:-

MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress(toAddress));
mail.From = new MailAddress(fromAddress, "Test");
mail.Subject = subject;
mail.IsBodyHtml = true;
mail.Body = body;

subject,body are string variables.


SmtpClient client = new SmtpClient(smtpServer, Convert.ToInt32(ConfigurationManager.AppSettings["port"]));
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Credentials = new NetworkCredential(smtpUser,smtpPassword);
client.Send(mail);
Sergey Alexandrovich Kryukov 12-Jun-16 11:22am    
But this part of code is irrelevant to the question; it does not say anything about the content. What's the problem? First of all, what should be those URLs, referencing images inside the mail, or outside, somewhere on the Web?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900