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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Dharmesh SharmaPosted Dec 26, 2012, 9:41 AM
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
Dharmesh SharmaPosted Dec 26, 2012, 2:48 PM
anandPosted Dec 26, 2012, 2:22 PM
thank you dharmesh sharma