Imports System.Net Imports System.Net.Mail Imports System.Drawing Imports System.Configuration Imports System.Data.SqlClient Partial Class login_ForgotPW Inherits System.Web.UI.Page Protected Sub btn_Back_Click(sender As Object, e As EventArgs) Response.Redirect("login/login_FLEX.aspx") End Sub Protected Sub SendEmail(sender As Object, e As EventArgs) Dim username As String = String.Empty Dim password As String = String.Empty ' cDBFunctions.GetNewOpenConnection() Dim ConnectionString = "" If HttpContext.Current.Request.ServerVariables("SERVER_NAME") = "localhost" Then 'ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=sa;Pwd=BmWr501956" ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;" Else ConnectionString = "Server=DEVELOPER.verag.ost.dmn\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;" 'ConnectionString = "Server=db593295684.db.1and1.com;Database=db593295684;Uid=dbo593295684;Pwd=atilla#2;" End If ' Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString Using con As New SqlConnection(ConnectionString) ' Using cmd As New SqlCommand("Validate_User") Using cmd As New SqlCommand("SELECT COUNT(*) FROM [VERAG_HOMEPAGE].[dbo].[Users] WHERE Username=@Username AND Password=@Password") ' cmd.CommandType = CommandType.StoredProcedure cmd.Connection = con con.Open() ' userId = Convert.ToInt32(cmd.ExecuteScalar()) Dim dr As SqlDataReader = cmd.ExecuteReader() If dr.Read() Then username = dr("@Username").ToString() password = dr("@Password").ToString() End If End Using con.Close() End Using If Not String.IsNullOrEmpty(password) Then ' SendEmail(username, password) lblMessage.ForeColor = Color.Green lblMessage.Text = "Password has been sent to your email address." Else lblMessage.ForeColor = Color.Red lblMessage.Text = "This email address does not match our records." End If End Sub Function SendEmail(username As String, password As String) As Boolean Dim Msg As New MailMessage Dim myCredentials As New System.Net.NetworkCredential myCredentials.UserName = "al@verag.ag" myCredentials.Password = "Luxandreas#2" Msg.IsBodyHtml = False Dim mySmtpsvr As New SmtpClient() mySmtpsvr.Host = "smtp.1und1.de" 'bei web.de mySmtpsvr.Port = 587 '25 mySmtpsvr.UseDefaultCredentials = False mySmtpsvr.Credentials = myCredentials Try Msg.From = New MailAddress("al@verag.ag") Msg.To.Add("al@verag.ag") Msg.Subject = "TEST" Msg.Body = String.Format("Hi {0},

Your password is {1}.

Thank You.", username, password) ' Dim attachment As Attachment = New Attachment(File.OpenRead(excel), "Kundenliste.xlsx") ' Msg.Attachments.Add(attachment) ' mySmtpsvr.Send(Msg) MsgBox("SENT") Return True Catch ex As Exception MsgBox(Err.Number & ex.Message & ex.StackTrace.ToString) 'Falls ein Fehler auftritt wird eine MsgBox angezeigt End Try Return False End Function End Class