
Email forwarding streamlines communication by automatically routing messages to the right recipients. This guide shows developers how to configure Outlook email forwarding programmatically using the Conholdate.Total library for Java and C#. Follow the steps to implement reliable forwarding in your applications.
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:
Java setup: Install the Conholdate.Total Outlook email forwarding library via Maven. Add the repository and dependency entries to your 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
For additional Java frameworks, visit releases.conholdate.com.
C# setup: Download the DLL or install the Outlook email forwarding library for C# via NuGet.
Install-Package Conholdate.Total
Step 2: Connect to Outlook:
Establish a connection to Outlook with Conholdate.Total by configuring the SmtpClient. Set the host, credentials, port, and security options as demonstrated.
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:
After connecting, load the source email message that you intend to forward. Use MailMessage.Load (C#) or MailMessage.load (Java) to read an .eml file.
C#:
MailMessage message = MailMessage.Load("Message.eml");
Java:
MailMessage message = MailMessage.load("Message.eml");
Step 4: Create and Send Forwarded Emails:
Create a forwarded message by calling the Forward method on the SmtpClient instance, passing recipient addresses and the original MailMessage.
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
Following this comprehensive guide, you can automate Outlook email forwarding with Conholdate.Total for both .NET and Java. Automating forwarding saves time, reduces manual effort, and improves communication flow. For advanced scenarios, consult the official Conholdate documentation and API references. 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.