Mail body as file

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
 
P

Patrice

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
 
D

Davide Vernole [MVP]

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,075
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top