I had this simple email example code, but when using the OpenNetCF an exception is thrown. Would someone know what is missing causing the exception to occur. I have and email sender working from the laptop but not from the WinCE device, so I know the local host and email addresses are correct. It appears to be something with OPENNETCF.
The code and exception are as follows:
Code:
using
System;
using
System.Linq;
using
System.Collections.Generic;
using
System.Text;
using
OpenNETCF.Net;
using
OpenNETCF.Net.Mail;public void SendMessage(string subject, string messageBody, string fromAddress, string toAddress, string ccAddress)
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();MailAddress address = new MailAddress(fromAddress);
// Set the sender's address
message.From = address;
// Allow multiple "To" addresses to be separated by a semi-colonif (toAddress.Trim().Length > 0)
{
foreach (string addr in toAddress.Split(';'))
{
message.To.Add(new MailAddress(addr));
}
}
// Allow multiple "Cc" addresses to be separated by a semi-colonif (ccAddress.Trim().Length > 0)
{
foreach (string addr in ccAddress.Split(';'))
{
message.CC.Add(new MailAddress(addr));
}
}
// Set the subject and message body text
message.Subject = subject;
message.Body = messageBody;
// TODO: *** Modify for your SMTP server ***
// Set the SMTP server to be used to send the messageclient.Host = "localhost";
// Send the e-mail message
try
{
client.Send(message);
}
catch (Exception e)
{
string data = e.ToString();
}
}
Exception:
"OpenNETCF.Net.Mail.SmtpException: SmtpException ---> System.NullReferenceException: NullReferenceException\r\n at OpenNETCF.Net.Mail.SmtpClient.SendInternal(MailMessage message)\r\n at OpenNETCF.Net.Mail.SmtpClient.Send(MailMessage message)\r\n at IMS_Galaxy.SendEmail.SendMessage(String subject, String messageBody, String fromAddress, String toAddress, String ccAddress)\r\n at IMS_Galaxy.BumpTest.removeInstrumentWhiteSpaces(String data)\r\n at IMS_Galaxy.BumpTest.determineCylinderAvailable()\r\n at IMS_Galaxy.BumpTest.BumpTestSequence(UInt32 command, Boolean success)\r\n at IMS_Galaxy.IRCommunications.IRSendMessage(Boolean portReceiveMessageReceived)\r\n at IMS_Galaxy.IMSGalaxyMainScreen.irPollTimer_Tick(Object sender, EventArgs e)\r\n at System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n at System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam)\r\n at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n at System.Windows.Forms.Application.Run(Form fm)\r\n at IMS_Galaxy.Program.Main()\r\n\r\n at OpenNETCF.Net.Mail.SmtpClient.Send(MailMessage message)\r\n at IMS_Galaxy.SendEmail.SendMessage(String subject, String messageBody, String fromAddress, String toAddress, String ccAddress)\r\n at IMS_Galaxy.BumpTest.removeInstrumentWhiteSpaces(String data)\r\n at IMS_Galaxy.BumpTest.determineCylinderAvailable()\r\n at IMS_Galaxy.BumpTest.BumpTestSequence(UInt32 command, Boolean success)\r\n at IMS_Galaxy.IRCommunications.IRSendMessage(Boolean portReceiveMessageReceived)\r\n at IMS_Galaxy.IMSGalaxyMainScreen.irPollTimer_Tick(Object sender, EventArgs e)\r\n at System.Windows.Forms.Timer._WnProc(WM wm, Int32 wParam, Int32 lParam)\r\n at System.Windows.Forms.ApplicationThreadContext._InternalContextMessages(WM wm, Int32 wParam, Int32 lParam)\r\n at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)\r\n at System.Windows.Forms.Application.Run(Form fm)\r\n at IMS_Galaxy.Program.Main()\r\n"
Thanks,