Outlook Email Forwarding

Email forwarding is an essential feature for efficient communication. In this blog post, we will explore how to set up email forwarding in Outlook using an Outlook email forwarding library for Java and C# programmers. It provides comprehensive functionalities for working with emails. Let’s get started and discover how to forward emails with ease.

Prerequisites:

We’ll use Conholdate.Total library for Outlook email forwarding. Before we get started, make sure you have the following:

  • An active or free temporary Conholdate.Total license for the Java or .NET version.
  • Familiarity with Java or C# programming languages.
  • A development environment such as IntelliJ IDEA or Visual Studio.
  • Basic knowledge of email management.

Step 1: Set Up Outlook Email Forwarding Library:

Set up for Java Development: If you are a Java developer, please install Java Outlook email forwarding library. The Maven users can add the following configurations in the pom.xml file.

<repository>
	<id>ConholdateJavaAPI</id>
	<name>Conholdate Java API</name>
	<url>https://releases.conholdate.com/java/repo</url>
</repository>        
<dependency>
	<groupId>com.conholdate</groupId>
	<artifactId>conholdate-total</artifactId>
	<version>23.6</version>
	<type>pom</type>
</dependency>

Then run the following commands.

mvn clean    
mvn install -U

To configure other Java frameworks, please visit releases.conholdate.com.

Set up for C# Programming: You can download the DLL or install this Outlook email forwarding library for C# using NuGet.

Install-Package Conholdate.Total 

Step 2: Connect to Outlook:

To establish a connection with Outlook using Conholdate.Total, proceed as follows:

  1. Create an instance of the SmtpClient class.
  2. Set the properties of the SmtpClient object, including the mailing host server, username, password, port, and security options.

C#:

//Create an instance of SmtpClient class
SmtpClient client = new SmtpClient();

// Specify your mailing host server, Username, Password, Port and SecurityOptions
client.Host = "mail.server.com";
client.Username = "username";
client.Password = "password";
client.Port = 587;
client.SecurityOptions = SecurityOptions.SSLExplicit;

Java:

// Create an instance of SmtpClient class
SmtpClient client = new SmtpClient();

// Specify your mailing host server, Username, Password, Port, and security options
client.setHost("mail.server.com");
client.setUsername("username");
client.setPassword("password");
client.setPort(587);
client.setSecurityOptions(SecurityOptions.SSLExplicit);

Step 3: Retrieve Emails for Forwarding:

Once connected to Outlook, you can fetch the emails you want to forward. Follow these steps:

  1. Load the email message using the MailMessage.Load method, providing the path to the EML file.
  2. Retrieve the necessary email data from the loaded MailMessage object.

C#:

MailMessage message = MailMessage.Load("Message.eml");

Java:

MailMessage message = MailMessage.load("Message.eml");

Step 4: Create and Send Forwarded Emails:

After fetching the emails, you can create new email objects for forwarding. Here’s how:

  1. Use the Forward method of the SmtpClient object to forward the original email.
  2. Specify the recipient’s email addresses and the MailMessage object as parameters.

C#:

client.Forward("Recipient1@domain.com", "Recipient2@domain.com", message);

Java:

client.forward("Recipient1@domain.com", "Recipient2@domain.com", message);

Complete Code

It is time to display the whole source code for both Java and C#:

C#:

//Create an instance of SmtpClient class
SmtpClient client = new SmtpClient();

// Specify your mailing host server, Username, Password, Port and SecurityOptions
client.Host = "mail.server.com";
client.Username = "username";
client.Password = "password";
client.Port = 587;
client.SecurityOptions = SecurityOptions.SSLExplicit;
MailMessage message = MailMessage.Load("Message.eml");

//Forward the email
client.Forward("Recipient1@domain.com", "Recipient2@domain.com", message);

Java:

// Create an instance of SmtpClient class
SmtpClient client = new SmtpClient();

// Specify your mailing host server, Username, Password, Port, and security options
client.setHost("mail.server.com");
client.setUsername("username");
client.setPassword("password");
client.setPort(587);
client.setSecurityOptions(SecurityOptions.SSLExplicit);
MailMessage message = MailMessage.load(dataDir + "Message.eml");
client.forward("Recipient1@domain.com", "Recipient2@domain.com", message);

Conclusion

By following this step-by-step guide, you can automate email forwarding in Outlook using Conholdate.Total for .NET and Java libraries. This will enhance productivity and streamline communication effortlessly. Remember to refer to the official documentation and APIs provided by Conholdate for detailed usage instructions and best practices. Happy coding!

Get a Free License

You can download a free temporary license to test the library without evaluation limitations.

Ask a Question

You can post your questions or comments in this forum.

See Also