C# SMPT

Last post 07-22-2010 15:45 by ctacke. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-22-2010 13:03

    C# SMPT

    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-colon

    if (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-colon

    if (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 message

    client.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,

  • 07-22-2010 13:09 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 2,255

    Re: C# SMPT

    The exception isn't overly helpful, no.  Just looking at the code, though, I see you're setting the client.Host to "localhost" which certainly can't be right - you CE device is not an SMTP server.

     

  • 07-22-2010 13:55 In reply to

    Re: C# SMPT

    Thanks,

     

    I know about the localhost.  I cannot post my server here, so that is not the issue. 

    The whole issue is that the exception is not helpful at all.

  • 07-22-2010 15:45 In reply to

    • ctacke
    • OpenNETCF Staff
    • Top 10 Contributor
    • Joined on 07-27-2007
    • Indiana
    • Posts 2,255

    Re: C# SMPT

    You're missing the Credential for the client.  You must provide the username, password and domain for your SMTP host.

Page 1 of 1 (4 items)