Add a string as a mail attachment text file.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry Viezel

    Add a string as a mail attachment text file.

    I have a string:

    sring Result = "This is the string I want sent as a text file"

    I have MailMessage:

    MailMessage TestMail = new MailMessage();
    TestMail.From = "larry.viezel@t mp.com";
    TestMail.To = "larry.viezel@t mp.com";
    TestMail.BodyFo rmat = MailFormat.Text ;
    TestMail.Subjec t = "Test email";
    TestMail.Body = "This would be the body of the email"


    I want to add Result as a textfile attachement to the email. How can I
    go about doing this? I would prefer if I didn't have to actually save
    to the disk.

    TestMail.Attach ments.Add(Resul t); //obviously this would be too
    easy.
    SmtpMail.Send(T estMail);

    Any thoughts? Can I somehow cast this string into a MailAttachment as
    if by magic?

    Larry.
  • Pete Wright

    #2
    Re: Add a string as a mail attachment text file.

    I think you are going to have to do the thing you don't want to do, which is
    persist the string to a file, and then attach the file. On the upside, once
    the mail is sent, there is nothing stopping your app from deleting the file.


    --
    Peter Wright
    Author of ADO.NET Novice To Pro, from Apress Inc.


    _______________ ______________
    "Larry Viezel" <larryv@nominex .com> wrote in message
    news:a3c92709.0 307100913.77911 e96@posting.goo gle.com...[color=blue]
    > I have a string:
    >
    > sring Result = "This is the string I want sent as a text file"
    >
    > I have MailMessage:
    >
    > MailMessage TestMail = new MailMessage();
    > TestMail.From = "larry.viezel@t mp.com";
    > TestMail.To = "larry.viezel@t mp.com";
    > TestMail.BodyFo rmat = MailFormat.Text ;
    > TestMail.Subjec t = "Test email";
    > TestMail.Body = "This would be the body of the email"
    >
    >
    > I want to add Result as a textfile attachement to the email. How can I
    > go about doing this? I would prefer if I didn't have to actually save
    > to the disk.
    >
    > TestMail.Attach ments.Add(Resul t); //obviously this would be too
    > easy.
    > SmtpMail.Send(T estMail);
    >
    > Any thoughts? Can I somehow cast this string into a MailAttachment as
    > if by magic?
    >
    > Larry.[/color]


    Comment

    • dave wanta

      #3
      Re: Add a string as a mail attachment text file.

      Yup, Pete's correct.

      You will have to create a text file and attach it.

      hth,
      Dave




      "Pete Wright" <pete@codemonke y.demon.co.uk> wrote in message news:<benc97$og q$17$8302bc10@n ews.demon.co.uk >...[color=blue]
      > I think you are going to have to do the thing you don't want to do, which is
      > persist the string to a file, and then attach the file. On the upside, once
      > the mail is sent, there is nothing stopping your app from deleting the file.
      >
      >
      > --
      > Peter Wright
      > Author of ADO.NET Novice To Pro, from Apress Inc.
      >
      >
      > _______________ ______________
      > "Larry Viezel" <larryv@nominex .com> wrote in message
      > news:a3c92709.0 307100913.77911 e96@posting.goo gle.com...[color=green]
      > > I have a string:
      > >
      > > sring Result = "This is the string I want sent as a text file"
      > >
      > > I have MailMessage:
      > >
      > > MailMessage TestMail = new MailMessage();
      > > TestMail.From = "larry.viezel@t mp.com";
      > > TestMail.To = "larry.viezel@t mp.com";
      > > TestMail.BodyFo rmat = MailFormat.Text ;
      > > TestMail.Subjec t = "Test email";
      > > TestMail.Body = "This would be the body of the email"
      > >
      > >
      > > I want to add Result as a textfile attachement to the email. How can I
      > > go about doing this? I would prefer if I didn't have to actually save
      > > to the disk.
      > >
      > > TestMail.Attach ments.Add(Resul t); //obviously this would be too
      > > easy.
      > > SmtpMail.Send(T estMail);
      > >
      > > Any thoughts? Can I somehow cast this string into a MailAttachment as
      > > if by magic?
      > >
      > > Larry.[/color][/color]

      Comment

      Working...