DiigIT | IT Community
No Profile Image
Welcome Guest
New User? Register | Login

Using .net and mail attachments

By: Admin | 10 Feb 2010 1:20 pm

All,

I have a simple .net form with a subject, body, a fileupload area to attach a file and an area for email address entry, So a basic page but when i try to send an email the code will not work, Any help would be great.

does anyone know how to send mail via .net here is my code and it will not send:

MailMessage message = new MailMessage( );
//set the addresses
message.From = new MailAddress( "xxxx@xx.xxx");
message.To.Add( strEmailsSelecte d);

//Create an instance of Attachment class
Attachment attachment;

attachment = new Attachment(FileUplo ad1.FileName) ;

//Add attachment in instance of MailMessage class
message.Attachments .Add(attachment) ;

//set the content
message.Subject = strEmailSubject;
message.Body = strEmailBody;

//send the message
SmtpClient client = new SmtpClient() ;

try
{
client.Send( message);
}
catch (Exception ex)
{
Console.WriteLine( "Exception caught in CreateMessageWithAt tachment( ): {0}",
ex.ToString( ));
}

message.Dispose( );

Comments

What exception you got? or it works fine and doesn't send anything?!

By: Admin | 10 Feb 2010
System.IO.FileNotFo undException

 - but the file does exists

By: Admin | 10 Feb 2010

Debug it! and sure the file doesn't exist!

Thank you,

By: Admin | 10 Feb 2010

Leave a comment

Enter the text in the image
img
Can't read?
Type the characters you see in the picture below.


Close Move