Mail pdf automatically that i have generated...
i want to mail a pdf that i havce generated.. i.e., if i clicked on a button than pdf will send automatically with its attachment.. plz provide solution.
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 attend4days leftRegister
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 9, 2017, 3:15 AM EST
parul jainRank #4,672 · 331 reputationPosted Feb 9, 2017, 6:41 PM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 9, 2017, 7:13 PM EST
Rafnas T PRank #280 · 8.8K reputationPosted Feb 10, 2017, 12:21 AM EST
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress("FromMailAddress");
message.To.Add(new MailAddress("ToMailAddress"));
message.Subject = "Test";
message.IsBodyHtml = true; //set true if you want to set body string as html
message.Body = " ";\\Body string
string attachmentFilename = @"E:\tt.pdf"; //FullFilePathWithExtension
if (attachmentFilename != null)
message.Attachments.Add(new Attachment(attachmentFilename)); //Attach here
smtp.Port = 587;
smtp.Host = "smtp.gmail.com"; //for gmail host
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("FromMailAddress", "password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Send(message);
}
catch (Exception)
{ }