I've learned that the .NET CF doesn't support a SmtpClient class. The best it has is the PocketOutlook class which I don't want to use.
I found that OpenNETCF does have a OpenNETCF.Net.Mail Namespace which makes the SmtpClient class available. It unfortunately is only partially implemented and does not support attachments directly: http://community.opennetcf.com/forums/t/11325.aspx
That post suggests that it is still possible to add an attachment using a multi-part MIME message.
Update
After reading ctacke's suggestion to look at the w3.org article I have attempted to change my method like so:
using OpenNETCF.Net.Mail;
public void EmailPicture(string picLoc)
{
var smtpClient = new SmtpClient
{
Host = MailProperties.SmtpHost,
Credentials = new SmtpCredential(MailProperties.UserName, MailProperties.Password, MailProperties.Domain),
DeliveryMethod = SmtpDeliveryMethod.Network,
Port = MailProperties.Port
};
var message = new MailMessage();
var fromAddress = new MailAddress(MailProperties.From);
message.To.Add(MailProperties.To);
message.From = fromAddress;
message.Subject = "Requested Picture";
message.IsBodyHtml = false;
message.Headers.Add("MIME-Version", "1.0");
message.Headers.Add("Content-Type", "multipart/mixed; boundary=\"simple boundary\"");
var bodyBuilder = new StringBuilder();
//add text
bodyBuilder.Append("--simple boundary\r\n");
bodyBuilder.Append("Content-type: text/plain; charset=us-ascii\r\n\r\n");
bodyBuilder.Append("Requested Picture is attached.\r\n\r\n");
//add attachment
bodyBuilder.Append("--simple boundary\r\n");
bodyBuilder.Append("Content-type: image/jpg;\r\n\r\n");
var fs = new FileStream(picLoc, FileMode.Open, FileAccess.Read);
var picData = new byte[fs.Length];
fs.Read(picData, 0, picData.Length);
bodyBuilder.Append(picData);
bodyBuilder.Append("\r\n\r\n");
bodyBuilder.Append("--simple boundry--\r\n");
message.Body = bodyBuilder.ToString();
smtpClient.Send(message);
}
The email I get ends up looking like this:
--simple boundary Content-type: text/plain; charset=us-ascii
Requested Picture is attached.
--simple boundary Content-type: image/jpg;
System.Byte[]
--simple boundry--
Do I have a format issue? or a missing header?