Mail body as file

  • Thread starter Thread starter Bnob
  • Start date Start date
B

Bnob

I am tring to send email using mail message class in asp.net using
VB.net language.
Can i use a *.txt file as the body arg in mail message class.

Any idea??

bye
 
You can attach files throught the Attachments property (see the SDK
documentation for details). You could also read the text file as a string
and store its content in the TextBody property...

Patrice
 
Bnob said:
I am tring to send email using mail message class in asp.net using
VB.net language.
Can i use a *.txt file as the body arg in mail message class.

Any idea??

bye

You could read the txt file and insert it in a StreamReader. Than read the
stream and create your body string.

e.g.
try
{
using (StreamReader sr = new StreamReader(@"MyFile.txt"))
{
String line;
StringBuilder sb = new StringBuilder();

while ((line = sr.ReadLine()) != null)
{
sb.Append(line);
}

string from = "(e-mail address removed)";
string to = "(e-mail address removed)";
string subject = "MySubject";
string body = sb.ToString();
SmtpMail.SmtpServer = "MyMailServer";
SmtpMail.Send(from, to, subject, body);

}
}
catch (Exception e)
{
//code to manage the exception
}

I write it without test the code, so I hope it's right !

HTH
 
Back
Top