View difference between Paste ID: b7b120hJ and 1e4DhWC9
SHOW: | | - or go back to the newest paste.
1
using System;
2
using System.Threading;
3
using Microsoft.SPOT;
4
using Gadgeteer.Networking;
5
using GT = Gadgeteer;
6
using GTM = Gadgeteer.Modules;
7
using Gadgeteer.Modules.GHIElectronics;
8
using Bansky.SPOT.Mail;
9
10
11-
namespace Gadgeteer_eMail_Banksey_01
11+
namespace Gadgeteer_Email_02
12
{
13
    public partial class Program
14
    {
15
        // This method is run when the mainboard is powered up or reset.   
16
        void ProgramStarted()
17
        {
18
            // jump to the StartWiFi method that starts the WiFi 
19
            StartWiFi();
20
21
            // create a button watching robot to trigger things when the button is pressed 
22
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
23
24
            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
25
            Debug.Print("Program Started");
26
27
        }
28
29
        void button_ButtonPressed(Button sender, Button.ButtonState state)
30
        {
31
            eMailBanksy();
32
        }
33
34
        void StartWiFi()
35
        {
36
            wifi.UseDHCP();
37
            Gadgeteer.Modules.GHIElectronics.WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
38-
            info.SSID = "RISD-Basic";
38+
            info.SSID = "R2HZL";
39
            info.SecMode = WiFi_RS21.SecurityMode.WEP;
40
            info.networkType = WiFi_RS21.NetworkType.AccessPoint;
41
            wifi.Join(info, "pass");
42
            wifi.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown);
43
            wifi.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp);
44
        }
45
46
        void wifi_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
47
        {
48
            Debug.Print("network down: connecting....");
49-
            
49+
50
        }
51
52
        void wifi_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
53
        {
54
            Debug.Print("network up");
55
            Debug.Print(wifi.NetworkSettings.IPAddress);
56-
            
56+
57
        }
58
59
60
        void eMailBanksy()
61
        {
62
63
            MailMessage message = new MailMessage();
64
            // Set sender name and address
65
            message.From = new MailAddress("[email protected]", "Andy Law");
66
67
            // Set recipient address            
68
            message.To.Add(new MailAddress("[email protected]", "Nic Villar"));
69
            message.Cc.Add(new MailAddress("[email protected]", "Andy Law"));
70
71
            message.Subject = "Hello World";
72
            message.Body = "Good news,<br />from now on you can send e-mails from <b>Gadgeteer .NET Micro Framework</b>.";
73
            // Format body as HTML
74
            message.IsBodyHtml = true;
75
76
            // Create new attachment and define it's name
77
            /*Attachment attachment = new Attachment("Snowflake.gif");
78
            attachment.ContentType = "image/gif";
79
            attachment.TransferEncoding = TransferEncoding.Base64;
80
            // Attachment content
81
            attachment.Content = Base64.Encode(Resources.GetBytes(
82
                                               Resources.BinaryResources.Snowflake_gif),
83
                                               true);
84
85
            // Add attachment to message
86
            message.Attachments.Add(attachment);
87
            */
88
            // Create new SMTP instance
89
            SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
90
            try
91
            {
92
                // Authenicate to server
93
                smtp.Authenticate = true;
94
                smtp.Username = "[email protected]";
95
                smtp.Password = "pass";
96
97
                // Send message
98
                smtp.Send(message);
99
            }
100
            catch (SmtpException e)
101
            {
102
                // Exception handling here 
103
                Debug.Print(e.Message);
104
                Debug.Print("Error Code: " + e.ErrorCode.ToString());
105
            }
106
            finally
107
            {
108
                smtp.Dispose();
109
            }
110
        }
111
    }
112
}