Hi,
I want to send e-mails with attachment, but i should not use the file upload control to attach.
How to do it?
Thanks in advance.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Dharmesh SharmaRank #1,974 · 741 reputationPosted Dec 26, 2012, 4:41 AM EST
void SendEmail(string email, string filepath)
{
string strPattern = "^([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
if (System.Text.RegularExpressions.Regex.IsMatch(email, strPattern))
{
string address = "[email protected]";
string addresses = email + "," + address;
string host = "mail.dhameshsharma.com";
string user = "[email protected]";
string pass = "abcd";
MailMessage message = new MailMessage();
message.From = new MailAddress(address);
message.To.Add(addresses);
message.IsBodyHtml = true;
message.Body = "Thank you for signing up to the ABCD, your invoice is attached";
message.Subject = "Invocie : ABCD Network";
Attachment inv = new Attachment(filepath);
message.Attachments.Add(inv);
GetSmtpClient(host, 0x19, user, pass, true).Send(message);
}
}
private static SmtpClient GetSmtpClient(string host, int port, string user, string password, bool enableSsl)
{
SmtpClient client = new SmtpClient();
client.Host = host;
client.Port = port;
NetworkCredential credential = new NetworkCredential(user, password);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
//client.Timeout = 0x1388;
client.Timeout = 99999;
client.Credentials = credential;
return client;
}
Thanks
anand3 reputationPosted Dec 26, 2012, 9:22 AM EST
thank you dharmesh sharma
Dharmesh SharmaRank #1,974 · 741 reputationPosted Dec 26, 2012, 9:48 AM EST