2013-01-17 5 views
0

j'ai créé un fichier HTML en utilisant constructeur de chaîne et l'a placé dans le répertoire courantattacher un fichier à un message

StreamWriter sw = new StreamWriter("../../Data.html"); 

Maintenant, je veux joindre ce fichier et l'envoyer un mail. Comment puis-je l'ajouter en pièce jointe à mon e-mail?

C'est ce que je fais plus ou moins avec un message html normal. Comment puis-je ajouter le fichier en pièce jointe?

public bool sendMailAttachment(string to, string from, string subject, string body, string attachment) 
    { 
     bool k = false; 
     try 
     { 
      SmtpClient client; 
      MailMessage msg = new MailMessage(from, to); 
      msg.Subject = subject; 
      msg.Body = body; 
      msg.IsBodyHtml = true; 

      client = new SmtpClient(); 
      client.Host = "staging.itmaniax.co.za"; 
      //client.Port = 25; 

      //**** 
      //client.EnableSsl = true; 
      client.Send(msg); 

      k = true; 

     } 
     catch (Exception exe) 
     { 
      Console.WriteLine(exe.ToString()); 
     } 
     return k; 
+0

Il y a une propriété Pièces jointes sur l'objet MailMessage .... –

+0

Avant de créer de nouvelles questions, s'il vous plaît regarder en arrière à vos questions précédentes et accepter toutes les réponses qui ont fonctionné pour vous ... par exemple, vous avez posé une question * très * similaire hier, qui a été répondu: http://stackoverflow.com/questions/14357877/trying-to-send-a-basic-email- to-folder – Arran

Répondre

1
Attachment attachment = new Attachment(attachmentPath); 
msg.Attachments.Add(attachment); 
+0

Il est à noter que si vous ne jetez pas correctement cette pièce jointe, gardera le fichier ouvert indéfiniment. –

Questions connexes