Netmf and SMTP

Hello. I am fairly new to this and I am trying to send an email with the FEZ Cobra II and I am having a bit of trouble. I have found several forums online about it but they seemed incomplete, in that they couldnt help me get this working. Here is the code I am using now:

using System;
using Microsoft.SPOT;
using Toolbox.NETMF.NET;
using Toolbox.NETMF;
using System.Threading;
using Microsoft.SPOT.Net;
using Microsoft.SPOT.Net.NetworkInformation;

namespace MFConsoleApplication1
{
    public class Program
    {
        

        public static void Main()
        {

            Debug.Print("working");

            // Defines the sender
            SMTP_Client.MailContact From = new SMTP_Client.MailContact("testercode@ gmail.com", "herron");

            // Defines the receiver
            SMTP_Client.MailContact Receiver = new SMTP_Client.MailContact("testercode@ gmail.com", "receiver");

            // Defines the mail message
            SMTP_Client.MailMessage Message = new SMTP_Client.MailMessage("Small test result");

            Message.Body = "This mail is sent by a Netduino :-)\r\n";
            Message.Body += "Good day!";
            // Initializes the mail sender class
            
            //string smtp = "smtp.gmail.com";
            string smtp = "server: aspmx.l.google.com" /*smtp.gmail.com tried this too*/ ;
            string username = "testcode";
            string pass = "Testercode7";
            SMTP_Client.AuthenticationTypes authtype = SMTP_Client.AuthenticationTypes.None;


            SMTP_Client Sender = new SMTP_Client(new IntegratedSocket(smtp, 25 /*465*/), authtype, username, pass);
         {
          //not sure what this host stuff is doing 

             // By default we fill the hostname with the name of the hardware itself. We need this to identify ourself
             
             string Hostname = Tools.HardwareProvider.ToString();
             int LastDot = Hostname.LastIndexOf('.');
             //JJ start
             if (LastDot > 0)
                 //JJ end
                 Hostname = Hostname.Substring(0, LastDot);
             //JJ start
                         
         }
         Sender.Send(Message, From, Receiver)

I forgot to say that I am getting this error
An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll
it seems to be where the object “Sender” is created
thanks

Welcome to the forum Herron

As Andre says, when you are pasting code into the forum, make sure you use CODE tags. Edit your post (use the pencil icon on the top right of your existing post that has code in it), then highlight just the code in question, hit the top left 101010 button (not the orange one below the text) and re-submit.

http://netmftoolbox.codeplex.com/wikipage?title=Toolbox.NETMF.NET.SMTP_Client is where you’re using the SMTP library from. I can’t say I’ve seen any discussion here on using this, but it shouldn’t be overly complex. I can also see that there’s not any discussion on issues with this on the codeplex site - although there’s not much discussion on the toolbox at all :frowning:

As I said, don’t know if too many people will have direct experience on this here, but some might be able to give it a try to see if they get the same issue.

Oh, forgot to mention, Garrcomm has posted here before, he may be along to show us the answer before we can test it for you :slight_smile:

OK, so step 1, please tell us about your network. Are you using Wifi or wired? Have you used your Cobra2 on the network before in any way? Do you have the networking set up at all - your code doesn’t seem to include any IP related setup, and that’s a possible cause of the issue.

@ Brett - there is no network!

yep, that’s what I established :wink:

hello brett. I am using ethernet, though I just did not put up that part of the code. Do you think that is what is causing the trouble? Thanks for the help.

We can’t really be sure, but that’s worth making sure we can see your code. And tell us how much you’ve used Ethernet in the past?

       private static void InitNetworking()
            {
                // First Display some information about networking
                NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

                if (networkInterfaces.Length == 0)
                    return;

                foreach (NetworkInterface ni in networkInterfaces)
                {
                    if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                    {
                        ni.EnableStaticIP("192.168.0.253", "255.255.255.0", "192.164.0.244");
                        ni.EnableStaticDns(new string[] { "4.2.2.1", "4.2.2.2" });

                        //ni.EnableStaticIP("192.168.253.2", "255.255.255.0", "192.164.243.1");
                        //ni.EnableStaticDns(new string[] { "4.2.2.1", "4.2.2.2" });

                    }
                }

Which Ethernet module are you using with your board?

The Cobra II has WiFi and you don’t seem to be enabling this.

Can I assume you have another Ethernet module plugged into the board?

at the moment i am testing on the EMX but yes the Cobra will have an ethernet port on it

@ herron - With MF 4.2 the initialization procedure for an Ethernet port changed. This info for the JD11 Ethernet module should put you on the right track. https://www.ghielectronics.com/docs/69/ethernet-j11d-module

ok thanks thats good to know, but for now id like to get this working on the EMX. Would that be the right initialization for the 4.1?

I tried using the enable Dhcp and I still got the same error. i dont know if i am using it correctly but here it is.

 private static void InitNetworking()
            {
                // First Display some information about networking
                NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();

                if (networkInterfaces.Length == 0)
                    return;

                foreach (NetworkInterface ni in networkInterfaces)
                {
                    if (ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet)
                    {
                        ni.EnableDhcp();
                        
                        ni.EnableStaticDns(new string[] { "4.2.2.1", "4.2.2.2" });

                       //ScreenWriter.Print("IP: " + networkInterfaces[0].IPAddress.ToString());
                    }
                }
            }


        }

If you are getting the exception on the following statement

SMTP_Client Sender = new SMTP_Client(new IntegratedSocket(smtp, 25 /*465*/), authtype, username, pass);

and have the source code for the toolkit, then single step with the debugger into the code and see where the exception is being thrown.

Ive stepped through and it stops there. I have a feeling it has to do with the socket, that may only be because I dont know much about it but does it matter if I do Simple or integrated. and when you do simple without the username and password, where is it sent?? thanks

An unhandled exception of type ‘System.Net.Sockets.SocketException’ occurred in Microsoft.SPOT.Net.dll

ok the sockets error went away but im still getting origional message still. im going to try a different library because i think his one has bugs