I have a simple little email app that allows a user to pick certain options that generate a string and sends out an email. I wanted to see if its possible to add images to the email i.e. a header logo or signature, etc. The research I’ve been looking at is very HTML heavy and I know very little HTML. Can anyone help? My code is as follows…
using System;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Configuration;
namespace My_EmailSender
{
public class EmailSender:Notification
{
string emailRecipient = ConfigurationManager.AppSettings["emailRecipient"];
public void SendMail(string message)
{
try
{
var oApp = new Outlook.Application();
var oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
var oRecip = (Outlook.Recipient)oMsg.Recipients.Add(emailRecipient);
oRecip.Resolve();
oMsg.Subject = "Email Notification";
oMsg.Body = message;
// Display the message before sending could save() also but no need
oMsg.Send();
oMsg.Display(true);
oRecip = null;
oMsg = null;
oApp = null;
}
catch (Exception e)
{
Console.WriteLine("Problem with email execution. Exception caught: ", e);
}
return;
}
}
}
I would always use
System.Net.Mailto send emails but maybe this is a requirement of yours?Read up on system.net.mail here.