Re: attach uploaded files to email

  •  03-16-2011, 1:24 AM

    Re: attach uploaded files to email

    Hi drifter,
     
     I tested your sample,
     You add attachments too early,
     The item.GetTempFilePath() returns the template path of item, it is a '.rex' file
     Before  you add attachments, you can use item.MoveTo(NEWPATH) method 
     
    This is my demo
     
    1. protected void Button1_Click(object sender, EventArgs e)  
    2.     {  
    3.         System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();  
    4.         msg.From = new System.Net.Mail.MailAddress("XXX@ccc.net");  
    5.         msg.To.Add("XXXXX@ccc.com");  
    6.         msg.Subject = "Nbk Jeff  please save";  
    7.         msg.Body = " as Such attachments";  
    8.   
    9.         foreach (AttachmentItem item in UploadAttachments1.Items)  
    10.         {  
    11.             if (!item.Checked) continue;  
    12.             //string filename = item.FileName;  
    13.             //int filesize=item.FileSize;  
    14.             //Stream stream = item.OpenStream();  
    15.             string attachmentPath = Server.MapPath("~/") + "UploadFiles\\" + item.FileGuid.ToString() + "_" + item.FileName;  
    16.             item.MoveTo(attachmentPath);  
    17.             System.Net.Mail.Attachment ma = new System.Net.Mail.Attachment(attachmentPath);  
    18.             msg.Attachments.Add(ma);  
    19.         }  
    20.         //System.Net.Mail.SmtpMail.Send(msg);  
    21.         System.Net.Mail.SmtpClient smtpClient = new System.Net.Mail.SmtpClient("smtp.ccc.com", 25);  
    22.         smtpClient.UseDefaultCredentials = false;  
    23.         smtpClient.Credentials = new System.Net.NetworkCredential("XXX@ccc.com""YOUR PASSWORD");  
    24.         smtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;  
    25.         smtpClient.Send(msg);  
    26.     }  
     
    Regards,
    Jeff 
View Complete Thread