Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using Microsoft.SPOT;
- using Gadgeteer.Networking;
- using GT = Gadgeteer;
- using GTM = Gadgeteer.Modules;
- using Gadgeteer.Modules.GHIElectronics;
- using Bansky.SPOT.Mail;
- namespace Gadgeteer_Email_02
- {
- public partial class Program
- {
- // This method is run when the mainboard is powered up or reset.
- void ProgramStarted()
- {
- // jump to the StartWiFi method that starts the WiFi
- StartWiFi();
- // create a button watching robot to trigger things when the button is pressed
- button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
- // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
- Debug.Print("Program Started");
- }
- void button_ButtonPressed(Button sender, Button.ButtonState state)
- {
- eMailBanksy();
- }
- void StartWiFi()
- {
- wifi.UseDHCP();
- Gadgeteer.Modules.GHIElectronics.WiFi_RS21.WiFiNetworkInfo info = new WiFi_RS21.WiFiNetworkInfo();
- info.SSID = "R2HZL";
- info.SecMode = WiFi_RS21.SecurityMode.WEP;
- info.networkType = WiFi_RS21.NetworkType.AccessPoint;
- wifi.Join(info, "pass");
- wifi.NetworkDown += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkDown);
- wifi.NetworkUp += new GTM.Module.NetworkModule.NetworkEventHandler(wifi_NetworkUp);
- }
- void wifi_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
- {
- Debug.Print("network down: connecting....");
- }
- void wifi_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
- {
- Debug.Print("network up");
- Debug.Print(wifi.NetworkSettings.IPAddress);
- }
- void eMailBanksy()
- {
- MailMessage message = new MailMessage();
- // Set sender name and address
- // Set recipient address
- message.Subject = "Hello World";
- message.Body = "Good news,<br />from now on you can send e-mails from <b>Gadgeteer .NET Micro Framework</b>.";
- // Format body as HTML
- message.IsBodyHtml = true;
- // Create new attachment and define it's name
- /*Attachment attachment = new Attachment("Snowflake.gif");
- attachment.ContentType = "image/gif";
- attachment.TransferEncoding = TransferEncoding.Base64;
- // Attachment content
- attachment.Content = Base64.Encode(Resources.GetBytes(
- Resources.BinaryResources.Snowflake_gif),
- true);
- // Add attachment to message
- message.Attachments.Add(attachment);
- */
- // Create new SMTP instance
- SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
- try
- {
- // Authenicate to server
- smtp.Authenticate = true;
- smtp.Password = "pass";
- // Send message
- smtp.Send(message);
- }
- catch (SmtpException e)
- {
- // Exception handling here
- Debug.Print(e.Message);
- Debug.Print("Error Code: " + e.ErrorCode.ToString());
- }
- finally
- {
- smtp.Dispose();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment