Invoke function into mail body in an email
-
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...
-
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...
:confused: Rephrase it, you aren't making much sense.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
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...
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
-
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