this.AddLogEntry("Creating message.");
// We create the message object
ActiveUp.Net.Mail.Message message = new ActiveUp.Net.Mail.Message();
// We assign the sender email
message.From.Email = this.fromEmailTextbox.Text;
// We assign the recipient email
message.To.Add(this.toEmailTextbox.Text);
// We assign the subject
message.Subject = this.subjectTextbox.Text;
// We add the embedded objets.
string bodyHtml = string.Empty;
for (int i = 0; i < _lvEmbeddedObject.Items.Count; i++)
{
message.EmbeddedObjects.Add((string)((Utils.ItemTag)_lvEmbeddedObject.Items[i]).Tag, true);
bodyHtml += "<img src = \"cid:" + message.EmbeddedObjects[i].ContentId + "\" />";
}
message.BodyHtml.Format = BodyFormat.Html;
if (bodyHtml.Length > 0)
{
message.BodyHtml.Text = bodyHtml;
}
else
{
message.BodyHtml.Text = "The message doens't contain embedded objects.";
}
// We send the email using the specified SMTP server
this.AddLogEntry("Sending message.");
try
{
message.Send(this.smtpServerAddressTextbox.Text);
this.AddLogEntry("Message sent successfully.");
}
catch (SmtpException ex)
{
this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
}
catch (Exception ex)
{
this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
}