Sign In  Sign Up Live-Chat

Aspose.Network

  • Aspose.Network for .NET v4.3.0.0 Released

    We have just released Aspose.Network for .NET v4.3.0.0.

    Outlook Message Files (*.msg) reading and writing features has been improved by introducing more new fuctions, like SetMessageFlags and SetStringPropertyValue.

    As long as Outlook featuers, Aspose.iCalendar is also integrated into Aspose.Network.

    Please check the release note and download the latest bits here:

    http://www.aspose.com/community/files/54/utility-components/aspose.network/default.aspx

  • Aspose.Network v4.2.0.0 Supports Outlook Message Files Reading/Writing

    We are proud to announce the new release of Aspose.Network v4.2.0.0. The long-awaited features for Outlook Message Files (*.msg) Writing have been completed and included in this release. Microsoft Outlook 2003, 2007, and 2008 are supported well.

    Another exciting feature in this release is that the Email Message Files (*.eml) is able to convert to Outlook Message Files (*.msg).

    You can now easily do the file format conversion in 1 line of code:

    MapiMessage.FromMailMessage("sample.eml").Save("sample.msg");

    For detail documentation of writing outlook message (msg) files, refer to http://www.aspose.com/documentation/utility-components/aspose.network-for-.net/creatingsaving-outlook-message-msg-files.html and for eml to msg conversion, please refer to http://www.aspose.com/documentation/utility-components/aspose.network-for-.net/eml-to-msg-converter.html.

    For download and release notes, please visit http://www.aspose.com/community/files/54/utility-components/aspose.network/default.aspx.

  • Aspose.Network for .NET v4.1.0.0 Released

    Aspose.Network for .NET v4.1.0.0 has been released. We provided more iCalendar feature in this release.

    Please check out the downlaod link:

    http://www.aspose.com/community/files/54/utility-components/aspose.network/default.aspx

  • Aspose.Network for .NET v4.0.0 Released

    Aspose.Network for .NET v4.0.0.0 comes with .NET framework 3.5 supports.

    Moreover, we also improved the Tnef attachment files decoding in this release. You don't need to care about the Tnef attachments (winmail.dat) in the eml files now. Just use MailMessage to load the file, we will decode the tnef file for you in the background.

    Check it out

    http://www.aspose.com/community/files/54/utility-components/aspose.network/default.aspx

  • Outlook Message (.msg) File Viewer

    We have added a new demo and an article for parsing and reading outlook message (.msg) files. You can now read outlook msg files using your own code. Microsoft Office Outlook is not required for it. A screenshot of the demo is shown below: 

    The demo can be downloaded from http://www.aspose.com/community/files/54/utility-components/aspose.network/entry130065.aspx. To read the article about how to implement it in your own application, please visit http://www.aspose.com/documentation/utility-components/aspose.network-for-.net/outlook-msg-file-viewer.html. The trial version of library can be downloaded from http://www.aspose.com/categories/utility-components/aspose.network-for-.net/default.aspx.

  • Aspose.Network for .NET v3.9.0.0 Released

    Aspose.Network for .NET v3.9.0.0 has released.

    In this major release, we supported S/MIME protocol features. Now you can add a digital signature to your email message.

    Here is the sample code:

           // load the certificate and associated private key from a file 
           X509Certificate2 certificate = X509Certificate2.LoadPfx("mycer.pfx", "password");

           // create an instance of MailMessage 
           MailMessage message = new MailMessage();

            // set its properties to desired values 
            message.From = "sender@domain.com";
            message.To = recipient@domain.com;
            message.Subject = "This is a signed message";
            message.TextBody = "Hello, world!";
            // attach a digital signature 
            message.AttachSignature(certificate);
            SmtpClient.Send(message);

    Download Link:

    http://www.aspose.com/community/files/54/utility-components/aspose.network/default.aspx

  • Aspose.Network v3.8.2.0 with Dns Mail

    We have released a new version of Aspose.Network. The majore feature of this release is Dns mail -- we now support sending email message with mail exchange servers if you don't have any smtp servers.

    Here is the code sample for C#:

                MailMessage msg = new MailMessage();
                msg.From = "sender@mail.com";
                msg.To = "use1@mail.com;user2@mail.com";
                msg.Subject = "dns sending";
                msg.Body = "it is a test.";
                DnsMailClient client = new DnsMailClient();
                client.Send(msg);

    By using the DnsMailClient class, you can send out an email message according to the mail exchange servers of the mail address itself. You don't need to have a valid smtp server now.

    However, it will also have some performance drop for Dns mail. Because in case of no smtp server, we need to talk to all of the different mail domains(if any) in order to send an email to all recipients. Let's say, if your email has two recipients in different mail host/domain, A is A@maildomain1.com, B is B@maildomain2.com. DnsMailClient will talk to maildomain1 and maildomain2 to send out emails.

    Therefore, Dns mail may be slow than the smtp mail, if you have lots of recipients in different mail domain.

    Here is the download page of Aspose.Network, Please check it out.

    http://www.aspose.com/community/files/54/utility-components/aspose.network/category1102.aspx

  • Access SSL Enabled SMTP Server (Gmail) via Aspose.Network for .NET

    In this article, we will show you how to access Gmail via SSL. We can access gmail using following protocols: 
    • SMTP
    • IMAP
    • POP3 

    SMTP

     

    In this section we will show you how to perform various tasks on Gmail server using SMTP protocol on SSL.

     

    Connect to Gmail SMTP server

     

    The following example shows you how you can connect to SSL enabled SMTP server. We will set the following properties for SSL support:

     

    ·          SecurityMode

    ·          EnableSSL

    ·          Port

     

    First create a new SmtpClient object as follows:

     

    [C#]

     

    Aspose.Network.Mail.SmtpClient client = new SmtpClient("smtp.gmail.com");

     

    [VB.Net]

     

    Dim client As Aspose.Network.Mail.SmtpClient = New SmtpClient("smtp.gmail.com")

     

    We have passed smtp.gmail.com in the constructor which is the smtp server address of Gmail. Now, set the following properties which are necessary to connect to any SSL enabled mail server.

     

    [C#]

     

    // set your Gmail username

    client.Username = "user@gmail.com";

    // set you Gmail password

    client.Password = "pwd";

    // set the port to 587. This is the SSL port of Gmail SMTP server

    client.Port = 587;

    // set the security mode to explicit

    client.SecurityMode = SmtpSslSecurityMode.Explicit;

    // enable SSL

    client.EnableSsl = true;

     

    [VB.Net]

     

    set your Gmail username

    client.Username = "user@gmail.com"

    ' set you Gmail password

    client.Password = "pwd"

    ' set the port to 587. This is the SSL port of Gmail SMTP server

    client.Port = 587

    ' set the security mode to explicit

    client.SecurityMode = SmtpSslSecurityMode.Explicit

    ' enable SSL

    client.EnableSsl = True

     

    Send an email message

     

    So far, we have setup the SMTP client object to connect to the Gmail server. To send a message using the above client object, we need to create a MailMessage object and send the message using SmtpClient object.

     

    [C#]

     

    Aspose.Network.Mail.MailMessage msg = new MailMessage();

     

    [VB.Net]

     

    Dim msg As Aspose.Network.Mail.MailMessage = New MailMessage()

     

    Set the properties of the message e.g. subject, to, body as follows:

     

    [C#]

     

    // from whom 

    msg.From = new Aspose.Network.Mail.MailAddress("user@gmail.com");

     

    // to whom

    msg.To.Add( new Aspose.Network.Mail.MailAddress( "user@gmail.com" ) );

     

    // set the subject

    msg.Subject = "subject";

     

    // set the priority

    msg.Priority = Aspose.Network.Mail.MailPriority.High;

     

    // set the message bodies

    msg.TextBody = "Please open with html browser";

    msg.HtmlBody = "<bold>this is the mail body</bold>";

                 

    // add the attachment

    Aspose.Network.Mail.Attachment attachment = new Attachment(@"c:\File.txt");

    msg.Attachments.Add(attachment);

     

    try

    {

    // send the message

    client.Send(msg);

    }

    // catch exception

    catch( SmtpException ex )

    {

    System.Diagnostics.Trace.WriteLine( ex.ToString() );

    }

     

    [VB.Net]

     

    ' from whom

    msg.From = New Aspose.Network.Mail.MailAddress("user@gmail.com")

     

    ' to whom

    msg.To.Add(New Aspose.Network.Mail.MailAddress("user@gmail.com"))

     

    ' set the subject

    msg.Subject = "subject"

     

    ' set the priority

    msg.Priority = Aspose.Network.Mail.MailPriority.High

     

    ' set the message bodies

    msg.TextBody = "Please open with html browser"

    msg.HtmlBody = "<bold>this is the mail body</bold>"

     

    ' add the attachment

    Dim attachment As Aspose.Network.Mail.Attachment = New Attachment("c:\File.txt")

    msg.Attachments.Add(attachment)

     

    Try

        ' send the message

        client.Send(msg)

    Catch ex As SmtpException

        ' catch exception

        System.Diagnostics.Trace.WriteLine(ex.ToString())

    End Try

     

    IMAP

     

    In this section we will perform some activities on SSL enabled mail server using IMAP protocol.

     

    Connect to the Mail Server

     

    We will use ImapClient object of Aspose.Network to connect to the mail server. Server’s address, port, username and password are required for the connection to be established. Gmail uses port 993 for IMAP protocol, so in our example below we will connect to gmail using the same port.

     

    Example:

     

    [C#]

     

    // connect to gmail server

    Aspose.Network.Imap.ImapClient imap = new Aspose.Network.Imap.ImapClient("imap.gmail.com", 993, "user@gmail.com", "pwd");

    imap.EnableSsl = true; // enable the SSL

    imap.SecurityMode = Aspose.Network.Imap.ImapSslSecurityMode.Implicit; // set security mode

    imap.Connect(true); // connect and login

     

    [VB.Net]

     

    ' connect to gmail server

    Dim imap As New Aspose.Network.Imap.ImapClient("imap.gmail.com", 993, "user@gmail.com", "pwd")

    imap.EnableSsl = True

    ' enable the SSL

    imap.SecurityMode = Aspose.Network.Imap.ImapSslSecurityMode.Implicit

    ' set security mode

    imap.Connect(True)

    ' connect and login

     

    Select Inbox folder and get total number of messages

     

    Checking Inbox is the most frequent task when you check your email. Using Aspose, this can be done using just 2 simple lines of code.

     

    Example:

     

    [C#]

     

    // select the Inbox folder

    imap.SelectFolder(ImapFolderInfo.InBox);

    //gets number of messages in the folder

    Console.WriteLine(imap.CurrentFolder.TotalMessageCount + " messages found.");

     

    [VB.Net]

     

    ' select the Inbox folder

    imap.SelectFolder(ImapFolderInfo.InBox)

    'gets number of messages in the folder

    Console.WriteLine(imap.CurrentFolder.TotalMessageCount + " messages found.")

     

    Saving messages to your local hard drive

     

    Once we select some folder using SelectFolder method, we can use ListMessages function to get the list of all the messages in that folder in an ImapMessagesInfoCollection object. We can iterate through this collection and save email messages to the local drive of computer as follows:

     

    Example:

     

    [C#]

     

    //gets the message info collection

    ImapMessageInfoCollection list = imap.ListMessages();

    //download each message

    for (int i = 0; i < list.Count; i++)

    {

       // save the message as eml file

       imap.SaveMessage(list[i].UniqueId, list[i].UniqueId + ".eml");

    }

     

    [VB.Net]

     

    'gets the message info collection

    Dim list As ImapMessageInfoCollection = imap.ListMessages()

    'download each message

    For i As Integer = 0 To list.Count - 1

        ' save the message as eml file

        imap.SaveMessage(list(i).UniqueId, list(i).UniqueId + ".eml")

    Next

     

    Create a new folder

     

    IMAP protocol also allows you to create a new folder on the email server for categorization of emails and store them in the appropriate folders. This can be done using a simple function call.

     

    Example:

     

    [C#]

     

    imap.CreateFolder("NewFolder");

     

    [VB.Net]

     

    imap.CreateFolder("NewFolder")

     

    Create a New message in a folder

     

    You can add a new message to the folder using the MailMessage and ImapClient class. We will create a MailMessage object first by providing subject, to and from. And then subscribe to a folder and add the message to it.

     

    Example:

     

    [C#]

     

    // create a message

    Aspose.Network.Mail.MailMessage msg;

       msg = new Aspose.Network.Mail.MailMessage(

       "user@gmail.com",

       "user@gmail.com",

       "subject",

       "message"

    );

     

    // subscribe to the currently selected folder which was Inbox in previous example

    imap.SubscribeFolder(imap.CurrentFolder.Name);

     

    // append the newly created message

    imap.AppendMessage(imap.CurrentFolder.Name, msg);

     

    [VB.Net]

     

    ' create a message

    Dim msg As Aspose.Network.Mail.MailMessage

    msg = New Aspose.Network.Mail.MailMessage("user@gmail.com", "user@gmail.com", "subject", "message")

     

    ' subscribe to the currently selected folder which was Inbox in previous example

    imap.SubscribeFolder(imap.CurrentFolder.Name)

     

    ' append the newly created message

    imap.AppendMessage(imap.CurrentFolder.Name, msg)

     

    Pop3

     

    In this section, we will show some examples that use Pop3 protocol on SSL. For SSL, we need to define the SSL port and 2 extra properties. Rest is same as connecting to normal Pop3 servers. We will start with making a connection to the mail server.

     

    Connecting to Mail server

     

    We will connect to the SSL enabled mail server using the same Pop3Client class as follows:

     

    Example:

     

    [C#]

     

    // create a pop3 client

    Aspose.Network.Pop3.Pop3Client client;

    client = new Aspose.Network.Pop3.Pop3Client();

     

    // basic setings (required)

    client.Host = "pop.gmail.com";

    client.Username = "user@gmail.com";

    client.Password = "pwd";

    client.Port = 995; // set SSL port

     

    // Settings required for SSL enabled Pop3 servers

    client.SecurityMode = Aspose.Network.Pop3.Pop3SslSecurityMode.Implicit; // set implicit security mode

    client.EnableSsl = true; // enable SSL

     

    client.Connect(); // establish a connection

    client.Login(); // login

     

    [VB.Net]

     

    ' create a pop3 client

    Dim client As Aspose.Network.Pop3.Pop3Client

    client = New Aspose.Network.Pop3.Pop3Client()

     

    ' basic setings (required)

    client.Host = "pop.gmail.com"

    client.Username = "user@gmail.com"

    client.Password = "pwd"

    client.Port = 995 ' set SSL port

     

    ' Settings required for SSL enabled Pop3 servers

    client.SecurityMode = Aspose.Network.Pop3.Pop3SslSecurityMode.Implicit ' set implicit security mode

    client.EnableSsl = True ' enable SSL

     

    client.Connect() ' establish a connection

    client.Login() ' login

     

    Check the mailbox status

     

    In this example, we will check the number of messages that are stored in the mailbox and the size of the mailbox. We will use Pop3MailboxInfo class for this purpose.

     

    Example:

     

    [C#]

     

    // create the object of type Pop3MailboxInfo

    Aspose.Network.Pop3.Pop3MailboxInfo info;

     

    // get the mailbox information

    info = client.GetMailboxInfo();

     

    // check number of messages

    Console.WriteLine(info.MessageCount);

     

    // check mailbox size

    Console.Write(info.OccupiedSize + " bytes");

     

    [VB.Net]

     

    ' create the object of type Pop3MailboxInfo

    Dim info As Aspose.Network.Pop3.Pop3MailboxInfo

     

    ' get the mailbox information

    info = client.GetMailboxInfo()

     

    ' check number of messages

    Console.WriteLine(info.MessageCount)

     

    ' check mailbox size

    Console.Write(info.OccupiedSize + " bytes")

     

    Check messages information in the mailbox

     

    In this example, we will check all the messages in the mailbox using Pop3MessageInfoCollection class. We will use Pop3Client.ListMessages() function to get the Pop3MessageInfoCollection. Then we will iterate through the collection to read the message information.

     

    Example:

     

    [C#]

     

    // get the list of messages in the mailbox

    Aspose.Network.Pop3.Pop3MessageInfoCollection infos = client.ListMessages();

                              

    // iterate through the messages

    foreach(Aspose.Network.Pop3.Pop3MessageInfo info in infos)

    {

       Console.Write("Id:" + info.UniqueId);

       Console.Write("Index number:" + info.SequenceNumber);

       Console.Write("Subject:" + info.Subject);

       Console.Write("size:" + info.Size);

    }

     

    [VB.Net]

     

    ' get the list of messages in the mailbox

    Dim infos As Aspose.Network.Pop3.Pop3MessageInfoCollection = client.ListMessages()

     

    ' iterate through the messages

    For Each info As Aspose.Network.Pop3.Pop3MessageInfo In infos

        Console.Write("Id:" + info.UniqueId)

        Console.Write("Index number:" + info.SequenceNumber)

        Console.Write("Subject:" + info.Subject)

        Console.Write("size:" + info.Size)

    Next

     

    Retrieve messages from the mailbox

     

    To get the messages from the mailbox we will use the FetchMessage() method of Pop3Client to get the message in a MailMessage type object.

     

    Example:

     

    [C#]

     

    // get number of messages in the mailbox

    int messageCount = client.GetMessageCount();

     

    // iterate through the messages and retrieve one by one

    for(int i=1; i<= messageCount; i++)

    {

           // create object of type MailMessage

    Aspose.Network.Mail.MailMessage msg;

          

           // retrieve the message in MimeMessage format directly

           msg = client.FetchMessage(i);

     

           Console.WriteLine("From:" + msg.From.ToString());

           Console.WriteLine("Subject:" + msg.Subject);

           Console.WriteLine(msg.HtmlBody);

     

           // save in local drive

    msg.Save(i + ".eml");

    }

     

    [VB.Net]

     

    ' get number of messages in the mailbox

    Dim messageCount As Integer = client.GetMessageCount()

    For i As Integer = 1 To messageCount

       

        ' iterate through the messages and retrieve one by one

        ' create object of type MailMessage

        Dim msg As Aspose.Network.Mail.MailMessage

       

        ' retrieve the message in MimeMessage format directly

        msg = client.FetchMessage(i)

       

        Console.WriteLine("From:" + msg.From.ToString())

        Console.WriteLine("Subject:" + msg.Subject)

        Console.WriteLine(msg.HtmlBody)

       

        ' save in local drive

        msg.Save(i + ".eml")

    Next