Click here to Skip to main content
15,999,481 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am generating a PDF file dynamically. Now i want to attach this file with email through code because i am sending mail dynamically without design any form for sending mail.
Posted
Comments
MDubey1987 25-Aug-10 7:10am    
Plz give ur answer with code if possible........

VB
Dim Attach As MailAttachment = New MailAttachment(filePath)
'creating an instance of MailAttachment class and specifying the location of attachment
mailMessage.Attachments.Add(Attach)
'adding the attachment to mailMessage
 
Share this answer
 
Comments
Dalek Dave 25-Aug-10 7:24am    
Yep. That's how I'd do it.
just add attachments to the mailmessage.
 
Share this answer
 
Comments
MDubey1987 25-Aug-10 7:09am    
I have try this but it not work.
public static void SendMailMessageWithAttachment(string to, string subject, string message,Attachment doc )
        {
            try
            {
                MailMessage mailMsg = new MailMessage();
                result = to.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int count = 0; count < result.Length; count++)
                {
                    mailMsg.To.Add(new MailAddress(result[count]));
                }
                mailMsg.From = new MailAddress(ConfigurationManager.AppSettings["FromEmail"]);
                mailMsg.Subject = subject;
                mailMsg.Body = message;
                mailMsg.Attachments.Add(doc);
                mailMsg.IsBodyHtml = true;
                SmtpClient smtpClient = new SmtpClient();

                //smtpClient.EnableSsl = true;
                //smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                smtpClient.Send(mailMsg);
            }
            catch (Exception exc)
            {
            }
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900