Hi,
is it possible to send e-mail via button on Display T35?
Hi,
is it possible to send e-mail via button on Display T35?
yes.
go to codeshare area and do a search on SMTP
The one does not depend on the other.
You can do anything an a button press, except making coffee (but I think there was a Gadgeteer Coffee Roster shortly :think:).
To send eMail, listen to @ Mike.
I found the example in codeshare. But what does mean
Error 3 The name âConvertBase64â does not exist in the current context
The code in Source.cs:
public void Send(string from, string recipient, string subject, string body,
bool authenticate = false, string username = ââ, string password = ââ)
{
if (username != ââ && password != ââ)
{
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
username = ConvertBase64.ToBase64String(encoding.GetBytes(username));
password = ConvertBase64.ToBase64String(encoding.GetBytes(password));
}
Am I missing a package?
There was a type in this code, change to following code:
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
username = Convert.ToBase64String(encoding.GetBytes(username));
password = Convert.ToBase64String(encoding.GetBytes(password));
I donât understand what you meanâŚ
I downloaded the example from:
https://www.ghielectronics.com/community/codeshare/entry/327
There are two cs files for sending e-mail. How can I use them to send the mail via a button_press_event?
GHIElectronics.NETMF.Glide.UI.Button buttonSend= (GHIElectronics.NETMF.Glide.UI.Button)window.GetChildByName(âSendâ);
buttonSend.PressEvent += new OnPress(button_SendPressEvent);
private void button_SendPressEvent(object sender)
{ how to fill this??
}
Ok sry,
I looked wrong. Iâll change the code, but my question regarding the use of the code example is still not answered
Take the Smtp client class into your project
put
SmtpClient mySmtp;
mySmtp = new SmtpClient(MAIL_SERVER, SMTP_PORT);
// Usage for anonymous (unauthenticated) Send...default parameter values will be used for auth params
mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY);
// Usage for authenticated Send - SMTP username and password will be base64 encoded by the
// Send method.
mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY, true, SMTP_USERNAME, SMTP_PASSWORD);
In your button handler and replace the âall capsâ words with your values.
This sniped I found in code share
https://www.ghielectronics.com/community/codeshare/entry/327
When clicking on the Usage link.
In your Button OnPress Event, add the following code:
SmtpClient mySmtp;
int SMTP_PORT = 25;
string MAIL_SERVER = "yourmailserveraddress";
string SENDER_ADDRESS = "sendersemailaddress";
string RECIPIENT_ADDRESS = "receipientsemailaddress";
string SUBJECT = "Your Subject";
string BODY = "This is a test Message";
string SMTP_USERNAME = "youremailaddress";
string SMTP_PASSWORD = "yourpassword";
mySmtp = new SmtpClient(MAIL_SERVER, SMTP_PORT);
// Usage for anonymous (unauthenticated) Send...default parameter values will be used for auth params
//mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY);
// Usage for authenticated Send - SMTP username and password will be base64 encoded by the
// Send method.
mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY, true, SMTP_USERNAME, SMTP_PASSWORD);
}
@ scardinale - Isnât that what I just wrote?
Yes. We must have been posting simultaneously.
@ scardinale - 1st 8)
I tried it but got the following error:
#### Message:
#### Microsoft.SPOT.Application::OnEvent [IP: 0090] ####
#### Microsoft.SPOT.EventSink::ProcessEvent [IP: 0023] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
A first chance exception of type âSystem.NullReferenceExceptionâ occurred in Microsoft.SPOT.TinyCore.dll
An unhandled exception of type âSystem.NullReferenceExceptionâ occurred in Microsoft.SPOT.TinyCore.dll
My code is:
SmtpClient mySmtp;
int SMTP_PORT = 25;
string MAIL_SERVER = âpop.gmail.comâ;
string SENDER_ADDRESS = âSB@ gmail.comâ;
string RECIPIENT_ADDRESS = âXY@ gmail.comâ;
string SUBJECT = âYour Subjectâ;
string BODY = âThis is a test Messageâ;
string SMTP_USERNAME = âSB@ gmail.comâ;
string SMTP_PASSWORD = âSBâ;
mySmtp = new SmtpClient(MAIL_SERVER, SMTP_PORT);
// Usage for anonymous (unauthenticated) SendâŚdefault parameter values will be used for auth params
//mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY);
// Usage for authenticated Send - SMTP username and password will be base64 encoded by the
// Send method.
mySmtp.Send(SENDER_ADDRESS, RECIPIENT_ADDRESS, SUBJECT, BODY, true, SMTP_USERNAME, SMTP_PASSWORD);
Iâ m not sure whether MAIL_SERVER is correct. I found some information in the internet but didnât know which one must be entered (s. attachment).
I used my original e-mail-adress with my correct password and recipient address was also my e-mail.
In file Source.cs I have seen:
public class SmtpClient
{
private string _SmtpServerName = null;
private int _Port = 0;
Is int_Port = 0 right?
Where did the exception occur? Did you try to diagnose this yourself? In particular, it says null reference, have you checked what code thatâs meant to be? Are you sure you have your events wired up correctly? Comment out the SMTP code and just do debug.print(âbutton pressedâ) and make sure that works before worrying about other stuff.
And please, you need to know your SMTP mail setup before you go into this. If you donât know you can get that to work, how will you know whether the problem is your code, or the settings? Use another SMTP program from a PC to make sure that works. GMail is a pretty bad choice to try to get working first time, do you have an email account on your local ISP for instance, theyâre usually much more simple to get working.
Now I have created a new project with only the display. (Ethernet is not added but plugged in FEZ)
I got the following error when I press on the button:
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### SmtpClient::Send [IP: 0048] ####
#### Button_Internet_Test.Program::Button_PressEvent [IP: 0045] ####
#### GHIElectronics.NETMF.Glide.UI.Button::TriggerPressEvent [IP: 000e] ####
#### GHIElectronics.NETMF.Glide.Display.DisplayObjectContainer::OnTouchDown [IP: 0035] ####
#### GHIElectronics.NETMF.Glide.Display.Window::TouchDownEvent [IP: 002e] ####
#### GHIElectronics.NETMF.Glide.TouchEventHandler::Invoke [IP: a0e0619a] ####
#### GHIElectronics.NETMF.Glide.GlideTouch::RaiseTouchDownEvent [IP: 0008] ####
#### GHIElectronics.NETMF.Glide.GlideTouch+TouchConnection::OnEvent [IP: 007f] ####
#### Microsoft.SPOT.EventSink::ProcessEvent [IP: 0023] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
An unhandled exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
Uncaught exception
What does mean socket exception?
I have replaced private int _Port = 0; by private int _Port = 80; Is that right?
The event_handler works because I see Debug.Print(âButton Pressed!â);
The error is thrown in this line in program.cs:
IPHostEntry SmtpServerHostEntry = Dns.GetHostEntry(_SmtpServerName);
I have the example from codeshare:
https://www.ghielectronics.com/community/codeshare/entry/327
Which one should I take as
int SMTP_PORT = 587;
string MAIL_SERVER = âsmtp.gmail.comâ;
(s.attachment)
Is private int _Port = 80; in Source.cs 80 or 0??
socket exception is a networking issue. You said you didnât include networking, but youâre trying to use networking. So a socket exception is telling you that you forgot to set up the networking.
Have you tried stepping into the code at all? That would be a really good move. Find a point of interest, set a break-point and run until you hit that and step in and see what happens.
My guess, without reading any code, is that the source.cs file is simply a DEFAULT value that gets overridden by what you pass in.
You need to specify the correct port. Only you know that, because it is what your mail server requires.
Iâve now looked at the source code in devhammerâs code. You can see the constructor overrides the port with whatever you use when you instantiate the class. So it doesnât matter what you put in source.cs, itâll be overwritten.
Also, his code doesnât use ssl.
Look at the âconfigure email clientâ page from your provider (GMX) to get the correct port.
You need the standard (non SSL) port.
The Defined standard for SMTP is 25 (80 is HTTP)
But some providers use a different port (like 2525) to make it âharderâ for hackers :
I think the line that initialized the port with â0â is ok, because itâs overwritten in the constructor by the provided parameter I think.
To find your NullReference exception you should step through the code to find the line where it happens.
Then start over, go to the line where it happened and stop there. Then check every variable, ⌠if itâs null.
NullReference exception appears only in my old project with other modules and functions.
I have created a new project with only the display and the button on the display. When I press the button I see on output window âButton Pressed!â. Then the code with smtp is executed. I set the breakpoint in line 47 source.cs:
IPHostEntry SmtpServerHostEntry = Dns.GetHostEntry(_SmtpServerName);
Until here there is no exception. When I press F11 (step into) the following error happens:
Step into: Stepping over non-user code 'System.Net.Dns.GetHostEntryâ
after few seconds:
#### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (4) ####
#### Message:
#### Microsoft.SPOT.Net.SocketNative::getaddrinfo [IP: 0000] ####
#### System.Net.Dns::GetHostEntry [IP: 0008] ####
#### SmtpClient::Send [IP: 0048] ####
#### Button_Internet_Test.Program::Button_PressEvent [IP: 0045] ####
#### GHIElectronics.NETMF.Glide.UI.Button::TriggerPressEvent [IP: 000e] ####
#### GHIElectronics.NETMF.Glide.Display.DisplayObjectContainer::OnTouchDown [IP: 0035] ####
#### GHIElectronics.NETMF.Glide.Display.Window::TouchDownEvent [IP: 002e] ####
#### GHIElectronics.NETMF.Glide.TouchEventHandler::Invoke [IP: a0e0619a] ####
#### GHIElectronics.NETMF.Glide.GlideTouch::RaiseTouchDownEvent [IP: 0008] ####
#### GHIElectronics.NETMF.Glide.GlideTouch+TouchConnection::OnEvent [IP: 007f] ####
#### Microsoft.SPOT.EventSink::ProcessEvent [IP: 0023] ####
#### Microsoft.SPOT.EventSink::EventDispatchCallback [IP: 0014] ####
#### SocketException ErrorCode = 10060
#### SocketException ErrorCode = 10060
A first chance exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.dll
#### SocketException ErrorCode = 10060
An unhandled exception of type âSystem.Net.Sockets.SocketExceptionâ occurred in Microsoft.SPOT.Net.dll
Since I need networking I plugged in the Ethernet J11 D. Is that right??
What can cause the socket exception??