Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Programmatically adding attachments to emails in C# and VB.NET[^]

Referring to the above article.


I set AspCompat="true" for page, then it working for my ASP.NET application.

But it is not working after hosting the app to server [Windows 2003].

We are using MAPI32.DLL in it.

MAPI32.DLL doesn't exist in Windows 2003?

Any idea?

Thanks
Posted

1 solution

here we have another way to send an email with attachment

C#
using System;
using System.Net.Mail;
using System.Net.Mime;

namespace Hugetiger
{

 public class HTSend_eMail
 {

  public void CreateMessageWithAttachment(String server, String pFN)
  {
   Console.WriteLine("\nTop CreateMessageWithAttachment");

   // Create a message and set up the recipients.
   MailMessage message = new MailMessage(
    "Alice@junk.com",  // from
    "Bob@junk.com", // to
    "The C# Letter", // subject
    "See the attached " + pFN);  // body

   // Create  the file attachment for this e-mail message.
   Attachment data = new Attachment(pFN, MediaTypeNames.Application.Octet);
   // Add time stamp information for the file.
   ContentDisposition disposition = data.ContentDisposition;
   disposition.CreationDate = System.IO.File.GetCreationTime(pFN);
   disposition.ModificationDate = System.IO.File.GetLastWriteTime(pFN);
   disposition.ReadDate = System.IO.File.GetLastAccessTime(pFN);
   // Add the file attachment to this e-mail message.
   message.Attachments.Add(data);
   //Send the message.
   SmtpClient client = new SmtpClient(server);
   // Add credentials if the SMTP server requires them.
   client.Credentials = new System.Net.NetworkCredential
      ("alice@junk.com", "mypassword");

   client.Send(message);
   // Display the values in the ContentDisposition for the attachment.
   /*
   ContentDisposition cd = data.ContentDisposition;
   Console.WriteLine("Content disposition");
   Console.WriteLine(cd.ToString());
   Console.WriteLine("File {0}", cd.FileName);
   Console.WriteLine("Size {0}", cd.Size);
   Console.WriteLine("Creation {0}", cd.CreationDate);
   Console.WriteLine("Modification {0}", cd.ModificationDate);
   Console.WriteLine("Read {0}", cd.ReadDate);
   Console.WriteLine("Inline {0}", cd.Inline);
   Console.WriteLine("Parameters: {0}", cd.Parameters.Count);
   foreach (DictionaryEntry d in cd.Parameters)
   {
    Console.WriteLine("{0} = {1}", d.Key, d.Value);
   }
    * */

   data.Dispose();
   Console.WriteLine("\nBot CreateMessageWithAttachment");

  }

 }
}
 
Share this answer
 
v3
Comments
derinpdavis 1-Jun-12 0:55am    
I need a email send popup instead sending on background

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