Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

image in mailmessage

Posted on 2006-07-24
11
Medium Priority
?
736 Views
Last Modified: 2008-01-09
In ASP.NET 2.0 with C# I have a mail withe image and text
I add the image and then the text exactly as it is written in all the resources and the image hide the text.
What's wrong in my kod???
Please help!!!!!!!!!!!!!!!!

  public static bool sendmail3(Page temppage)
    {
        MailMessage myMessage = new MailMessage();

        myMessage.To.Add(new MailAddress("anat@business-solutions.co.il"));
        myMessage.From = new MailAddress("anat@business-solutions.co.il");
        myMessage.Subject = "How are you";

        ContentType HtmlContentType = new ContentType("text/html");
        AlternateView HtmlView = AlternateView.CreateAlternateViewFromString("</b><img src=cid:JustinPic><b></b>", HtmlContentType);
        LinkedResource SomePic = new LinkedResource(@"C:\anat\images\update.gif");
        SomePic.ContentId = "JustinPic";
        HtmlView.LinkedResources.Add(SomePic);
        myMessage.AlternateViews.Add(HtmlView);

        ContentType PlainContentType = new ContentType("text/plain");
        AlternateView PlainView = AlternateView.CreateAlternateViewFromString("Hi, This is a text and I wish to see this text!!!!", PlainContentType);
        myMessage.AlternateViews.Add(PlainView);

        System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
        smtp.Send(myMessage);

        return true;

    }

0
Comment
Question by:ANAT2403
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +1
11 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17167588
Hi ANAT2403,

you need to give it a full web reference: www.mysite.com/images/myimage.jpg

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17167594
sorry misunderstood, did you say that the imagecovers the text?
0
 

Author Comment

by:ANAT2403
ID: 17167738
Yes.
If I give only the image I see it perfect
If I give only the text I see it perfect.
If I give both as in the kod I see only the text.
If I concat the image to the kod in html mode I see both but the text loses its format and comes in one long line.
Anat
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ANAT2403
ID: 17168099
I also discovered that it does not concern the image but the HTML text
The followin code also hide the text:

      AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is the plain text view", new ContentType("text/plain"));
        AlternateView htmlView = AlternateView.CreateAlternateViewFromString("", new ContentType("text/html"));

       msg.AlternateViews.Add(htmlView);
       msg.AlternateViews.Add(plainView);
0
 
LVL 7

Expert Comment

by:skvikram
ID: 17169348
Try this:

<%@ Import Namespace="System.Web.Mail" %>
<%@ Import Namespace="System.IO" %>
<%
Dim objMailMessage As MailMessage
Dim swHTMLBody As StringWriter
Dim twTextWriter As HtmlTextWriter

swHTMLBody = New StringWriter
twTextWriter = New HtmlTextWriter( swHTMLBody )

twTextWriter.RenderBeginTag( "html" )
twTextWriter.RenderBeginTag( "head" )
twTextWriter.RenderBeginTag( "title" )
twTextWriter.Write( "Thank You!" )
twTextWriter.RenderEndTag
twTextWriter.RenderEndTag
twTextWriter.AddAttribute( "bgcolor", "lightblue" )
twTextWriter.RenderBeginTag( "body" )
twTextWriter.AddAttribute( "src", "aspnet.gif" )
twTextWriter.RenderBeginTag( "img" )
twTextWriter.RenderEndTag
twTextWriter.RenderEndTag
twTextWriter.RenderEndTag

' Create the Mail Message
objMailMessage = New MailMessage
objMailMessage.From = "you@somewhere.com"
objMailMessage.To = "joe@somewhere.com"
objMailMessage.Subject = "Here's the image!"
objMailMessage.Body = swHTMLBody.ToString
objMailMessage.BodyFormat = MailFormat.HTML
objMailMessage.UrlContentLocation = "http://www.yourdomain.com/"

' Send the Mail Message
SmtpMail.Send( objMailMessage )
%>
Image Sent!
0
 

Author Comment

by:ANAT2403
ID: 17173918
seems interesting. I will transform it to C# and try it and inform you.
By the way what is the purpose of the line
objMailMessage.UrlContentLocation = "http://www.yourdomain.com/"?
Is it necessary?

0
 

Author Comment

by:ANAT2403
ID: 17174653
Hi skvikram.
It's very nice what you gave and I learned from you how to create a twTextWriter  object but I finally
solve my problem by myself in a very simple way:
I found out that I have to have one body that consist of the image and the text  and this should
be in the AlternateView.CreateAlternateViewFromString as text HTML.
But this gives me a mail with an image and the text comes after it as one long text not formatted.
All I did is: I went to the text where it was defined and in each line I added at the end - the sign of end line - "<br />".
And that's it. now the text comes formatted. I did not have to create the twTextWriter . It was enough that
I declared it as a string with the AlternateView as html.
Thanks anyhow
Anat
0
 
LVL 7

Expert Comment

by:skvikram
ID: 17175443
Dear Administrator, Page Editors,
For your kind notice :

ANAT2403  asked three questions as follows with almost the same problem:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21928822.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21928772.html
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21929525.html

and then mysteriously he found out the solution all by himself. After seeing, I beleive some good expert comments.
Then he requested the withdrawal of questions with points refunded.
How this can be possible that after seeing an alternative answer (May be from this ANAT2403 may have got hint from) you can withdraw the question.

THIS IS COMPLETELY AGAINST THE COMMUNITY PRINCIPAL.
0
 

Author Comment

by:ANAT2403
ID: 17175800
dear skvikram,
First of all I am she and not he.
It's true I asked the question 3 times because nobody gave me the solution and for a whole day I looked
everywhere to find it and I couldn't find it. So I asked again maybe someone else will have an idea.
(I was once told from the administrators of this site that if I don't get the appropriate answer I can  ask the question again because the experts react the question a short time after it appears and then it is reacted less).
I gave you the solution and you saw it. Do you see in the solution something that you or someone else gave?
Believe me I would be happy to give you or anybody else the points but as I understand the rules of this site say not to
do it. I don't earn anything from the refunded points. I pay each month 10$ to get answers and all I want
is to get the correct answers. I develop a project alone and I have no one to advise with and this site
helps me alot. I know that you try to help me alot when I ask questions and you know that I don't
hesitate to accept answers. The truth is that I am a bit offended from this comment of you.
What would you do if you were in my place?
Anat
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17220181
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question