این یه متد واسه اینکار
public static string SendMessageWithAttachment(string sendTo, string
sendFrom, string sendSubject, string sendMessage, ArrayList
attachments)
{
try
{
// validate email address
bool bTest = ValidateEmailAddress(sendTo);
if (bTest == false)
return "Invalid recipient email address: " + sendTo;
// Create the basic message
MailMessage message = new MailMessage(
sendFrom,
sendTo,
sendSubject,
sendMessage);
// The attachments array should point to a file location
// where
// the attachment resides - add the attachments to the
// message
foreach (string attach in attachments)
{
Attachment attached = new Attachment(attach,
MediaTypeNames.Application.Octet);
message.Attachments.Add(attached);
}
// create smtp client at mail server location
SmtpClient client = new
SmtpClient(Properties.Settings.Default.SMTPAddress );
// Add credentials
client.UseDefaultCredentials = true;
// send message
client.Send(message);
return "Message sent to " + sendTo + " at " +
DateTime.Now.ToString() + ".";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
منبع