In this lab exercise we will learn how to send an email from a C# console application using the MailKit library.
-
Download the following:
-
Create an "app password" by following the steps listed here. PLEASE USE A THROW-AWAY ACCOUNT FOR THIS LAB.
-
Open Visual Studio and select the Clone a repository option. Input the URL of this repository (https://github.com/csce361Github/IntroEmailApplication.git) and click the Clone button.
-
Navigate to
Program.csand modify the name, email address, username, and password (there areTODOcomments showing you where to update the code). -
Run the application by hitting the green, outlined play button (Start Without Debugging) or by hitting
Ctrl + F5. Send an email and ensure that the program works correctly.Note: if you are getting errors such as "the MailKit package cannot be found in the Microsoft Visual Studio Offline Packages" or something similar, in the menu bar navigate to
Project -> Manage NuGet Packagesand ensure that you have nuget.org as a Package Source. If not, click the settings icon to the right of the dropdown, click the green plus button, and add the following package source:Name: nuget.org Source: https://api.nuget.org/v3/index.json
Click update and then hit OK. This should allow you to now access the nuget.org in the Package Source dropdown.
You should be able to properly run the project, but if you are still missing the MailKit package, you might not have the MailKit package installed and will need to manually install it. Navigate back to the NuGet Package Manager and install MailKit.
-
Add
try-catchblocks where appropriate. -
Add meaningful comments to the code.
-
Take some time to hover over the various classes used and get comfortable with Intellisense in Visual Studio. Turn in the
Program.csfile when you are done.
-
Download the following:
- .NET 8.0
- Visual Studio Code
C#extension from MicrosoftVisual NuGetextension from Full Stack Spider
-
Create an "app password" by following the steps listed here. PLEASE USE A THROW-AWAY ACCOUNT FOR THIS LAB.
-
Clone this repository to your local machine and open the project in Visual Studio Code.
-
Navigate to
Program.csand modify the name, email address, username, and password (there areTODOcomments showing you where to update the code). -
Right-click on the
IntroEmailApplication.csprojfile, select Visual Nuget: Manage Packages, and install the MailKit package. -
Run the program by opening a terminal instance in the
IntroEmailApplication/IntroEmailApplicationdirectory and running the following command:dotnet run
Send an email and ensure that the program works correctly.
-
Add
try-catchblocks where appropriate. -
Add meaningful comments to the code.
-
Take some time to hover over the various classes used and get comfortable with Intellisense in Visual Studio Code. Turn in the
Program.csfile when you are done.
For those of you that are more comfortable with C#, use the basics outlined in this code to create a Windows Forms project. Modify this code to now capture the details from these UI elements and send the email.