You would think taking  attachments from a  Sharepoint list and adding them to a mail message would be easy.  Well, not that easy.  They make you jump through hoops and stream the attachment with the file name.  Would have been nice to just take an attachment off a list and then add it to an email using the same attachment object.  Oh well.  Here’s the code I use to take an attachment off a list item, look at the file name, then attach it to an email using System.Mail.

 MailMessage mail = new MailMessage(); 

 SmtpClient smtp = new SmtpClient this.workflowProperties.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address); 
 mail.Subject = “Subject”
mail.To.Add(wfConfig.EmailTo);
mail.CC.Add(wfConfig.EmailCC);
mail.From = new MailAddress(wfConfig.EmailFrom);
mail.Body =”body”:
mail.IsBodyHtml = true;

 

 //Attachment(s)  
 

 if (workflowProperties.Item.Attachments.Count > 0)
{
      foreach (string fileName in workflowProperties.Item.Attachments)
     {
      SPFile file = workflowProperties.Item.ParentList.ParentWeb.GetFile(
         
workflowProperties.Item.Attachments.UrlPrefix + fileName);
    
          
if (file.Name.ToUpper().Contains(DocNameToCheck))
         
{
            Attachment attachment = new Attachment(file.OpenBinaryStream(), fileName, string.Empty);
            
mail.Attachments.Add(attachment);
           smtp.Send(mail);
        
}//if  
 
   
}//foreach

}//if
 
 

 

 

 foreach (string fileName inworkflowProperties.Item.Attachments)