Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Invoke function into mail body in an email

Invoke function into mail body in an email

Scheduled Pinned Locked Moved C#
question
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zafax_
    wrote on last edited by
    #1

    Hi guys i had solution which im confusing that how a body of mail takes streamreader's colllection from a text file. How can i do this? can anyone give me a suggestion, would be great! function readtext reads a myfile.txt and i want invoke this method to mail.Body. by send mail event. private static void readtext() { FileStream fs = new FileStream("C:\\myfile.txt", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); sw.BaseStream.Seek(0, SeekOrigin.Begin); string str = sw.ReadLine(); while (str != null) { str = sr.ReadLine(); } sr.Close(); fs.Close(); } } thanks!

    so much of happy ending...

    P S 2 Replies Last reply
    0
    • Z zafax_

      Hi guys i had solution which im confusing that how a body of mail takes streamreader's colllection from a text file. How can i do this? can anyone give me a suggestion, would be great! function readtext reads a myfile.txt and i want invoke this method to mail.Body. by send mail event. private static void readtext() { FileStream fs = new FileStream("C:\\myfile.txt", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); sw.BaseStream.Seek(0, SeekOrigin.Begin); string str = sw.ReadLine(); while (str != null) { str = sr.ReadLine(); } sr.Close(); fs.Close(); } } thanks!

      so much of happy ending...

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #2

      :confused: Rephrase it, you aren't making much sense.

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer

      1 Reply Last reply
      0
      • Z zafax_

        Hi guys i had solution which im confusing that how a body of mail takes streamreader's colllection from a text file. How can i do this? can anyone give me a suggestion, would be great! function readtext reads a myfile.txt and i want invoke this method to mail.Body. by send mail event. private static void readtext() { FileStream fs = new FileStream("C:\\myfile.txt", FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs); sw.BaseStream.Seek(0, SeekOrigin.Begin); string str = sw.ReadLine(); while (str != null) { str = sr.ReadLine(); } sr.Close(); fs.Close(); } } thanks!

        so much of happy ending...

        S Offline
        S Offline
        Skippums
        wrote on last edited by
        #3

        Look into System.Net.Mail (specifically the MailMessage and SmtpClient classes) to send the emails. Also, your method should return the string it is building. Perhaps you should do something like the following (be careful if the file can be large, as it may throw a memory overflow exception)...

        private static string ReadText(string fullFilePath) {
        FileStream fs = null;
        StreamReader sr = null;
        try {
        fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read);
        sr = new StreamReader(fs);
        return sr.ReadToEnd();
        } finally {
        if (sr != null)
        sr.Close();
        if (fs != null)
        fs.Close();
        }
        }

        Alternatively, you could send the file as an attachment. Examples of this can be found when you examine the MailMessage class. Hope this helps,

        Sounds like somebody's got a case of the Mondays -Jeff

        Z 1 Reply Last reply
        0
        • S Skippums

          Look into System.Net.Mail (specifically the MailMessage and SmtpClient classes) to send the emails. Also, your method should return the string it is building. Perhaps you should do something like the following (be careful if the file can be large, as it may throw a memory overflow exception)...

          private static string ReadText(string fullFilePath) {
          FileStream fs = null;
          StreamReader sr = null;
          try {
          fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read);
          sr = new StreamReader(fs);
          return sr.ReadToEnd();
          } finally {
          if (sr != null)
          sr.Close();
          if (fs != null)
          fs.Close();
          }
          }

          Alternatively, you could send the file as an attachment. Examples of this can be found when you examine the MailMessage class. Hope this helps,

          Sounds like somebody's got a case of the Mondays -Jeff

          Z Offline
          Z Offline
          zafax_
          wrote on last edited by
          #4

          thanks, its really helpful!! jeff.

          so much of happy ending...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups