views:

43

answers:

4

Hi guys,

I'm trying to use the PasswordRecovery of ASP.NET.

Everything works fine, however I am using Email template. Within this email I'm trying to insert an image as follows:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;

<body>

<img alt="blabla" src="/Images/blabla-logo.png" align="middle"/><br/><br/>
bla bla:<%Password%><br /><br />
</body>

</html>

As I said, the email is being sent fine but the image is not inserted. I tried: src="~/Images/blabla-logo.png", but with no success.

Idea anyone?

Thanks a lot, Assaf.

A: 

You can use OnSendingMail event to modify your email message. Let's assume your template look like this:

<html xmlns="http://www.w3.org/1999/xhtml"&gt;
  <body>
    <img alt="blabla" src="{0}" align="middle"/><br/><br/> 
    bla bla:<%Password%><br /><br /> 
  </body>
</html>

You PasswordRecovery markup should look like this:

<asp:PasswordRecovery ID="prPasswordRecovery" runat="server" OnSendingMail="prPasswordRecovery_SendingMail">
  <MailDefinition BodyFileName="~/passwordRecoveryEmailTemplate.txt" IsBodyHtml="true" Priority="High" Subject="bla bla"/>
</asp:PasswordRecovery>

Last thing to do is to write prPasswordRecovery_SendingMail method in code behind:

protected void prPasswordRecovery_SendingMail(object sender, MailMessageEventArgs e)
{
  e.Message.Body = String.Format(e.Message.Body, ResolveClientUrl("~/Images/blabla-logo.png"));
}

That should do it.

tpeczek
Thank you so much. I don't see any reason why this should not work. I must be doing something wrong but I tried this and it didn't work. I'm still getting the email without the image.By the way, I gave the email template the .htm extension, and the VS marks the src="{0}" part and tells me that the file is not found. Should I be using text file? is that important?Thank you both for the help, you are really the best.
Assaf
A: 

try adding a tilde "~", an id and runat="server". The tilde only gets changed to the root path when runat="server" is applied. Otherwise, the serverside code has no knowledge of the control and doesn't parse it and apply the path insertion

 <img alt="blabla" src="~/Images/blabla-logo.png" 
 align="middle" id="img" runat="server"/>
Daniel Dyson
Thank you so much for your help. This all seems very reasonable. However, I tried it but it didn't work. I tried to struggle with it a bit but with no success. Thanks a lot.
Assaf
Try opening the page in Firefox and then open the firebug plugin to see the path that is being erendered. Is the image in the Images directory in the root of your site? Also, try removing the hyphen from the image name and from the link. There are different types of hyphen and they might not match
Daniel Dyson
+1  A: 

For email you should not give relative path like "/Images/blabla-logo.png" the only works for the internal website pages, instead of this you should give the complete path like

http://youserver/youapp/Images/blabla-logo.png

I will suggest you not to include image using the path instead of this try embedding the image in your email.

Prakash Kalakoti
Thats what I do. Always refer to the "live" image on the "live" server with the complete path.
Simon
A: 

Have you tried using AlternateView?

One example is here.

SP249
If you want the C# example then you can have a look at the following link.http://www.codeproject.com/KB/aspnet/inkrajesh.aspx
SP249