Solved

AlternateView in mailmessage hide the body

Posted on 2006-07-23
11
1,915 Views
Last Modified: 2012-08-14
I have a mailmessage with an image in it that I add with AlternateView .

 AlternateView htmlView = AlternateView.CreateAlternateViewFromString("<img src=cid:companylogo>", null, "text/html");
            LinkedResource logo = new LinkedResource("C:\\anat\\images\\iibmailg.gif");
            logo.ContentId = "companylogo";
            htmlView.LinkedResources.Add(logo);
            message.AlternateViews.Add(htmlView);

When I add this I lose the body of my message. although I write
message.Body = "test email1......."
I don't see the body but only the image.
What is the problem here?
0
Comment
Question by:ANAT2403
  • 5
  • 3
11 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17163665
You could create an AlternateView this way:

AlternateView htmlView= new AlternateView(body, MediaTypeNames.Text.Html);
message.AlternateViews.Add(htmlView);

Bob
0
 

Author Comment

by:ANAT2403
ID: 17164146
I managed to see both the image and the text but the image is seen only when it is in mode text.Html
and in this situation the text loses all its style format and appear as one long line.
How do I solve a situation like this that I have an image an a formatted text?
Anat
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17164911
Another way that might be useful is the Text.RichText type.

Bob
0
Gigs: Get Your Project Delivered by an Expert

Select from 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.

 

Author Comment

by:ANAT2403
ID: 17167547
I don't understand, I write it exactly as it is shown in all the resources and the image hide the text.
What's wrong here? 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
 

Author Comment

by:ANAT2403
ID: 17168113
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
 

Accepted Solution

by:
ANAT2403 earned 0 total points
ID: 17174660
This is the solution:
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.
Anat
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17174727
Crap--all you needed was <br>.  I hate when I can't get the easy answers.  I don't use the AlternateView, so I was thinking it was a problem with the arguments.

Thanks,
Bob
0
 
LVL 7

Expert Comment

by:skvikram
ID: 17175441
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: 17175796
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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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