Images in HTML

Discussion in 'ASP .Net' started by T.Michelle, Jan 24, 2004.

  1. T.Michelle

    T.Michelle Guest

    We have few Mail templates (.html) which we

    use to send mails.

    We want to have some Logo in that ie ... when I send the mail to user the

    image should go as in-line embedded

    image in mail. I am not able to get this. I tried with

    Message.Attachments.add ... but its sending the image

    as an attachment. Please note I do not want to give any website URL to those

    images coz we would be sending mails

    to some users who do not have Internet Access. They should be able to see

    the Images Offline.

    I searched over the net ... and got to know that I have to use PAID third

    party tools. I can not believe this.

    coz in my 9 yrs experience I have never come across a situation where I

    could not achieve something with Microsoft.

    Do I have to use Cid (ContentId) ? If YES .. kindly let me know how do I

    generate this Cid ?

    Kindly let me know how to send HTML mails with in-line embedded images using

    C# and ASP.Net
    T.Michelle, Jan 24, 2004
    #1
    1. Advertising

  2. T.Michelle

    Ruprict Guest

    Hi,

    This should just be a matter of setting your src attributes to the image
    name and attaching each image to the mail.

    This works for me:

    // Put user code to initialize the page here\
    MailMessage mail = new MailMessage();
    mail.To="";
    SmtpMail.SmtpServer="localhost";
    mail.From="";
    mail.Attachments.Add(new MailAttachment("c:\\temp\\progressbar.gif"));
    mail.BodyFormat=System.Web.Mail.MailFormat.Html;
    mail.Body="<html><body>test<img src='progressbar.gif'/></body></html>";
    SmtpMail.Send(mail);


    Hope this helps....


    T.Michelle wrote:

    > We have few Mail templates (.html) which we
    >
    > use to send mails.
    >
    > We want to have some Logo in that ie ... when I send the mail to user the
    >
    > image should go as in-line embedded
    >
    > image in mail. I am not able to get this. I tried with
    >
    > Message.Attachments.add ... but its sending the image
    >
    > as an attachment. Please note I do not want to give any website URL to those
    >
    > images coz we would be sending mails
    >
    > to some users who do not have Internet Access. They should be able to see
    >
    > the Images Offline.
    >
    > I searched over the net ... and got to know that I have to use PAID third
    >
    > party tools. I can not believe this.
    >
    > coz in my 9 yrs experience I have never come across a situation where I
    >
    > could not achieve something with Microsoft.
    >
    > Do I have to use Cid (ContentId) ? If YES .. kindly let me know how do I
    >
    > generate this Cid ?
    >
    > Kindly let me know how to send HTML mails with in-line embedded images using
    >
    > C# and ASP.Net
    >
    >
    Ruprict, Jan 24, 2004
    #2
    1. Advertising

  3. T.Michelle

    Jerry III Guest

    No it won't help, to do that you have to send the e-mail as MIME formatted,
    mutlipart/related content type. MailMessage doesn't support this, you need
    to write your own class (or find one) that does.

    Jerry

    "Ruprict" <> wrote in message
    news:HltQb.26831$...
    > Hi,
    >
    > This should just be a matter of setting your src attributes to the image
    > name and attaching each image to the mail.
    >
    > This works for me:
    >
    > // Put user code to initialize the page here\
    > MailMessage mail = new MailMessage();
    > mail.To="";
    > SmtpMail.SmtpServer="localhost";
    > mail.From="";
    > mail.Attachments.Add(new MailAttachment("c:\\temp\\progressbar.gif"));
    > mail.BodyFormat=System.Web.Mail.MailFormat.Html;
    > mail.Body="<html><body>test<img src='progressbar.gif'/></body></html>";
    > SmtpMail.Send(mail);
    >
    >
    > Hope this helps....
    >
    >
    > T.Michelle wrote:
    >
    > > We have few Mail templates (.html) which we
    > >
    > > use to send mails.
    > >
    > > We want to have some Logo in that ie ... when I send the mail to user

    the
    > >
    > > image should go as in-line embedded
    > >
    > > image in mail. I am not able to get this. I tried with
    > >
    > > Message.Attachments.add ... but its sending the image
    > >
    > > as an attachment. Please note I do not want to give any website URL to

    those
    > >
    > > images coz we would be sending mails
    > >
    > > to some users who do not have Internet Access. They should be able to

    see
    > >
    > > the Images Offline.
    > >
    > > I searched over the net ... and got to know that I have to use PAID

    third
    > >
    > > party tools. I can not believe this.
    > >
    > > coz in my 9 yrs experience I have never come across a situation where I
    > >
    > > could not achieve something with Microsoft.
    > >
    > > Do I have to use Cid (ContentId) ? If YES .. kindly let me know how do I
    > >
    > > generate this Cid ?
    > >
    > > Kindly let me know how to send HTML mails with in-line embedded images

    using
    > >
    > > C# and ASP.Net
    > >
    > >
    Jerry III, Jan 25, 2004
    #3
  4. "Jerry III" <> wrote in news:eXr1fP44DHA.2576
    @TK2MSFTNGP11.phx.gbl:
    > No it won't help, to do that you have to send the e-mail as MIME
    > mutlipart/related content type. MailMessage doesn't support this, you
    > to write your own class (or find one) that does.


    http://www.indyproject.org/indy.html

    Fully supports MIME and more in messages. Its absolutely free too. :)

    If you need help with writing sample code for Indy, you can ask here or in
    the Indy newsgroups.

    >> > I searched over the net ... and got to know that I have to use PAID

    > third
    >> >
    >> > party tools. I can not believe this.


    Third party, but not paid. :)

    >> > coz in my 9 yrs experience I have never come across a situation where I
    >> > could not achieve something with Microsoft.


    Im not sure what you've been doing, but its a daily experience for me. :)


    --
    Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    "Programming is an art form that fights back"


    ELKNews - Get your free copy at http://www.atozedsoftware.com
    Chad Z. Hower aka Kudzu, Jan 25, 2004
    #4
  5. T.Michelle

    Ruprict Guest

    But I did it and it WORKED. Image was inline just as I specified. I
    even tried various HTML tags on the page to move the image around (put
    it in a <ul> for example) and it worked. In T. Michelle's case, he
    would probably have to build the template in code, but it should still
    work out of the box.

    Excuse my ignorance, but I am just wondering what I am missing if my
    images are showing up inline....

    Did you try the code below? Does it matter that I am running IIS?

    Jerry III wrote:

    > No it won't help, to do that you have to send the e-mail as MIME formatted,
    > mutlipart/related content type. MailMessage doesn't support this, you need
    > to write your own class (or find one) that does.
    >
    > Jerry
    >
    > "Ruprict" <> wrote in message
    > news:HltQb.26831$...
    >
    >>Hi,
    >>
    >>This should just be a matter of setting your src attributes to the image
    >>name and attaching each image to the mail.
    >>
    >>This works for me:
    >>
    >>// Put user code to initialize the page here\
    >>MailMessage mail = new MailMessage();
    >>mail.To="";
    >>SmtpMail.SmtpServer="localhost";
    >>mail.From="";
    >>mail.Attachments.Add(new MailAttachment("c:\\temp\\progressbar.gif"));
    >>mail.BodyFormat=System.Web.Mail.MailFormat.Html;
    >>mail.Body="<html><body>test<img src='progressbar.gif'/></body></html>";
    >>SmtpMail.Send(mail);
    >>
    >>
    >>Hope this helps....
    >>
    >>
    >>T.Michelle wrote:
    >>
    >>
    >>>We have few Mail templates (.html) which we
    >>>
    >>>use to send mails.
    >>>
    >>>We want to have some Logo in that ie ... when I send the mail to user

    >
    > the
    >
    >>>image should go as in-line embedded
    >>>
    >>>image in mail. I am not able to get this. I tried with
    >>>
    >>>Message.Attachments.add ... but its sending the image
    >>>
    >>>as an attachment. Please note I do not want to give any website URL to

    >
    > those
    >
    >>>images coz we would be sending mails
    >>>
    >>>to some users who do not have Internet Access. They should be able to

    >
    > see
    >
    >>>the Images Offline.
    >>>
    >>>I searched over the net ... and got to know that I have to use PAID

    >
    > third
    >
    >>>party tools. I can not believe this.
    >>>
    >>>coz in my 9 yrs experience I have never come across a situation where I
    >>>
    >>>could not achieve something with Microsoft.
    >>>
    >>>Do I have to use Cid (ContentId) ? If YES .. kindly let me know how do I
    >>>
    >>>generate this Cid ?
    >>>
    >>>Kindly let me know how to send HTML mails with in-line embedded images

    >
    > using
    >
    >>>C# and ASP.Net
    >>>
    >>>

    >
    >
    >
    Ruprict, Jan 25, 2004
    #5
  6. Ruprict <> wrote in
    news:kLWQb.17999$:
    > But I did it and it WORKED. Image was inline just as I specified. I
    > even tried various HTML tags on the page to move the image around (put
    > it in a <ul> for example) and it worked. In T. Michelle's case, he
    > would probably have to build the template in code, but it should still
    > work out of the box.


    What mail client did you use to look at it with? On quick glance its not a
    compliant message, and you are just lucky that the client you used is fixing
    it up. You will very likely have less success if at all with most clients.

    > Does it matter that I am running IIS?


    No. Mail servers generally do not modify mail.


    --
    Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    "Programming is an art form that fights back"


    ELKNews - Get your free copy at http://www.atozedsoftware.com
    Chad Z. Hower aka Kudzu, Jan 25, 2004
    #6
  7. T.Michelle

    Ruprict Guest

    I was using Outlook for initial tests, but I just tried it with
    Thunderbird and no dice....


    So, the problem seems to be mail clients, not the MailMessage object
    itself....yes? Or maybe a combo of both?

    Thanks for the knowledge, btw.

    Chad Z. Hower aka Kudzu wrote:

    > Ruprict <> wrote in
    > news:kLWQb.17999$:
    >
    >>But I did it and it WORKED. Image was inline just as I specified. I
    >>even tried various HTML tags on the page to move the image around (put
    >>it in a <ul> for example) and it worked. In T. Michelle's case, he
    >>would probably have to build the template in code, but it should still
    >>work out of the box.

    >
    >
    > What mail client did you use to look at it with? On quick glance its not a
    > compliant message, and you are just lucky that the client you used is fixing
    > it up. You will very likely have less success if at all with most clients.
    >
    >
    >>Does it matter that I am running IIS?

    >
    >
    > No. Mail servers generally do not modify mail.
    >
    >
    > --
    > Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    > "Programming is an art form that fights back"
    >
    >
    > ELKNews - Get your free copy at http://www.atozedsoftware.com
    >
    Ruprict, Jan 25, 2004
    #7
  8. Ruprict <> wrote in
    news:R3XQb.18237$:
    > So, the problem seems to be mail clients, not the MailMessage object


    NOOO!!! I knew you were using Outlook. Outlook like IE fixed up all kinds of
    poorly and non standard type HTML.

    Which is good - EXCEPT that people use Outlook and IE to "verify" and then
    assume they have good HTML (or mail messages). They then later find out
    Netscape or something doesnt like it and blame it, when really its their
    code. Netscape and others follow the standards much closer to the letter and
    dont try to do fix ups.

    You can probably do it with MailMessage, but its going to be a nightmare
    managing all the headers and trying to get the mime markers exactly right.

    Indy does all of this for you and is free - Unless you are opposed to using
    something that is free, has over a million deployments, is well supported,
    and works.....

    http://www.indyproject.org/indy.html


    --
    Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    "Programming is an art form that fights back"


    ELKNews - Get your free copy at http://www.atozedsoftware.com
    Chad Z. Hower aka Kudzu, Jan 25, 2004
    #8
  9. T.Michelle

    Hermit Dave Guest

    Well not necessarily correct. In my experience netscape doesnt follow most
    standards to full extent.
    Atleast ie is forgiving with things. NS just comes out as a necessary evil
    (considering it still has a 5% market)

    --
    Regards,
    HD
    Once a Geek.... Always a Geek
    "Chad Z. Hower aka Kudzu" <> wrote in message
    news:Xns947CF4E51302cpub@127.0.0.1...
    > Ruprict <> wrote in
    > news:R3XQb.18237$:
    >> So, the problem seems to be mail clients, not the MailMessage object

    >
    > NOOO!!! I knew you were using Outlook. Outlook like IE fixed up all kinds
    > of
    > poorly and non standard type HTML.
    >
    > Which is good - EXCEPT that people use Outlook and IE to "verify" and then
    > assume they have good HTML (or mail messages). They then later find out
    > Netscape or something doesnt like it and blame it, when really its their
    > code. Netscape and others follow the standards much closer to the letter
    > and
    > dont try to do fix ups.
    >
    > You can probably do it with MailMessage, but its going to be a nightmare
    > managing all the headers and trying to get the mime markers exactly right.
    >
    > Indy does all of this for you and is free - Unless you are opposed to
    > using
    > something that is free, has over a million deployments, is well supported,
    > and works.....
    >
    > http://www.indyproject.org/indy.html
    >
    >
    > --
    > Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    > "Programming is an art form that fights back"
    >
    >
    > ELKNews - Get your free copy at http://www.atozedsoftware.com
    >
    Hermit Dave, Jan 25, 2004
    #9
  10. "Hermit Dave" <> wrote in news:OWi
    $:
    > Well not necessarily correct. In my experience netscape doesnt follow most
    > standards to full extent.


    NS4 is old. The newer NS is quite strict about standards.

    > Atleast ie is forgiving with things. NS just comes out as a necessary evil
    > (considering it still has a 5% market)


    Its not only NS. Most other mailers follow the standards pretty strict.
    Outlook and IE are the ones that "fix up" things, and this causes the
    problems I mentioned because people use them as verification.

    If you write badly formed code, dont blame the non MS tools when they dont
    interpret it correctly. Its like asking Uncle Bubba to help you with you
    spelling test and then getting mad at your teacher for correcting you.


    --
    Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
    "Programming is an art form that fights back"


    ELKNews - Get your free copy at http://www.atozedsoftware.com
    Chad Z. Hower aka Kudzu, Jan 26, 2004
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Sutter
    Replies:
    0
    Views:
    634
    John Sutter
    Jan 13, 2004
  2. Guest
    Replies:
    4
    Views:
    890
    Eliyahu Goldin
    Jan 4, 2005
  3. Luis Esteban Valencia Muñoz
    Replies:
    0
    Views:
    768
    Luis Esteban Valencia Muñoz
    Jun 3, 2005
  4. wardemon

    Cache Images vs Static Images

    wardemon, Jun 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    657
    bruce barker
    Jun 14, 2007
  5. Keith Hughitt
    Replies:
    6
    Views:
    1,067
Loading...

Share This Page