2

I want to allow the user of the handheld device software I'm working on to send me email (the contents of a log file, which will have exception data and other info for debugging).

How can I do that? All the user should have to do, on seeing the contents of the log file (which I display to them on-demand in a form), is to mash a "send this" button. The contents of the log file (which can be read from the Textbox in which they are displaying) can be the body of the email message (rather than an attachment), with the subject line being something like "{user name} log contents"

If I have to prompt the user for their email address, that's probably okay, but I would prefer to use one of our email addresses as the sender, so that it's seen as being both from us and to us (probably two different accounts, though).

B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • 1
    What mail protocol do you need to use? Does this need to be more complex than just creating a TCP connection to an [SMTP](https://tools.ietf.org/html/rfc821) server? – PaulH Jan 14 '15 at 18:00
  • I don't know which protocol - whatever is available in this "world" (Windows CE/Compact Framework). IOW, I don't know how to determine the answer to your question. – B. Clay Shannon-B. Crow Raven Jan 14 '15 at 18:08
  • 1
    I don't think any protocol is natively supported by the OS. So, my question is "what protocols are supported by the mail server you want to communicate with?" If your intended mail server supports SMTP, then this is very easy. They don't call it "simple mail" for nothing. – PaulH Jan 14 '15 at 18:22
  • I don't know the answer to that, either. I was hoping there was an easy and universal way to "just do it." – B. Clay Shannon-B. Crow Raven Jan 14 '15 at 18:35

1 Answers1

2

One way would to use the SDF and the OpenNETCF.Net.Mail namespace objects. It works like the System.Net.Mail objects, so sending an email would look something like this:

var message = new MailMessage();

message.From = new MailAddress("sender@mydomain.com");
message.To.Add(new MailAddress("recipient@domain.com"));
message.Subject = "Hello World";
message.Body = "This is my message body";

var client = new SmtpClient();

client.Host = "smtp.myserver.com";
client.Credentials = new SmtpCredential("myusername", "mypassword", "mydomain");

client.Send(message);
ctacke
  • 66,480
  • 18
  • 94
  • 155