12
« on: June 13, 2017, 10:09:27 PM »
Hello I have a small problem with sending email when I do code myself and I press button1 its works very well but when I use the function emailler1 its not working. I use visual studio 2015.
Imports System.Web
Imports System.IO
Imports System.Net.Mail
Public Class MainForm
'*******************************************************************************
'* Stop polling when the form is not visible in order to reduce communications
'* Copy this section of code to every new form created
'*******************************************************************************
Private NotFirstShow As Boolean
Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
'* Do not start comms on first show in case it was set to disable in design mode
If NotFirstShow Then
AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
Else
NotFirstShow = True
End If
End Sub
'***************************************************************
'* .NET does not close hidden forms, so do it here
'* to make sure forms are disposed and drivers close
'***************************************************************
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim index As Integer
While index < My.Application.OpenForms.Count
If My.Application.OpenForms(index) IsNot Me Then
My.Application.OpenForms(index).Close()
End If
index += 1
End While
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Buttontest.Click
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("sebastienduhaime@gmail.com", "xxxxxx")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("sebastienduhaime@gmail.com")
e_mail.To.Add("sebastienduhaime@live.ca")
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = TxtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
End Sub
Private Sub DataSubscriber1_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
End Sub
End Class
Here are the mistakes I have when I use emailler:
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.Net.Mail.SmtpException' dans System.dll
Exception levée : 'System.Net.Mail.SmtpException' dans System.dll
Exception levée : 'System.Net.Mail.SmtpException' dans System.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Exception levée : 'System.NullReferenceException' dans AdvancedHMIControls.dll
Le thread 0x28d8 s'est arrêté avec le code 0 (0x0).
Le thread 0x3edc s'est arrêté avec le code 0 (0x0).
Le thread 0x359c s'est arrêté avec le code 0 (0x0).
Le thread 0x3784 s'est arrêté avec le code 0 (0x0).
Le programme '[15132] AdvancedHMI.vshost.exe' s'est arrêté avec le code 0 (0x0).
thanks and best regard!!!
Sebastien Duhaime