Using MailBee.NET Objects in Azure cloud

MailBee.NET Objects library is fully compatible with Microsoft Azure. You can use it just the same way you do on a normal PC.

For instance, let’s assume you have an ASP.NET MVC5 web app which you publish on Azure. You can modify Controllers/HtmlController.cs as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.IO;
using MailBee;
using MailBee.ImapMail;

namespace WebApplicationAzure.Controllers
{
	public class HomeController : Controller
	{
		public ActionResult Index()
		{
			return View();
		}

		public ActionResult About()
		{
			ViewBag.Message = "Your application description page.";
			MailBee.Global.LicenseKey = "your key";
			Imap imp = new Imap();
			string logPath = Path.Combine(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath, "log.txt");
			imp.Log.Filename = logPath;
			imp.Log.Enabled = true;
			imp.Log.Clear();
			try
			{
				imp.Connect("mail.domain.com");
				imp.Login("your@account.com", "password");
				FolderCollection col = imp.DownloadFolders();
				imp.Disconnect();
				ViewBag.Message = $"Number of folders: {col.Count}, log path is {logPath}";
			}
			catch (MailBeeException ex)
			{
				ViewBag.Message = ex.ToString();
			}
			ViewBag.Log = System.IO.File.ReadAllText(logPath);
			return View();
		}

		public ActionResult Contact()
		{
			ViewBag.Message = "Your contact page.";

			return View();
		}
	}
}

Views/Home/About.cshtml looks like:

@{
    ViewBag.Title = "About";
}
<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>
<pre>@ViewBag.Log</pre>
<p>Use this area to provide additional information.</p>

 

Don’t forget to add a reference to MailBee.NET library via Nuget.

Now, when you publish the app and navigate to About page, this will display the number of folders in an IMAP account and the contents of the log file produced by MailBee.

Advertisements
Using MailBee.NET Objects in Azure cloud

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s