我的想法是制作一个(忘记密码)表格,该表格将还原(用户名)和(密码)并通过用户提供的电子邮件地址发送。 在下图中,客户将输入他的电子邮件地址,因此过程代码将在隐藏工作表中找到该电子邮件地址的完全匹配项,如果存在匹配项,则接下来的两个单元格将作为字符串存储。
正如您在下面看到的那样,这是一个隐藏的工作表,其中包含一个表,其中包含有关注册客户的信息,因此当我们收到与(Username)和(Password)相匹配的电子邮件时,将其存储为字符串((!!看到这张纸!!)
现在是我当前的代码,希望您能解决它:
Public Function send_email()
Dim NUser As String
Dim NPass As String
Dim info As Variant
Set cdomsg = CreateObject("CDO.message")
With cdomsg.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = "587"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "dash32762@gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "*******"
.Update
End With
' ========(( below is the code i want to find and store user and pass ))
Set info = Worksheets("AdminPanel2").Range("I11:I80").Find( _
What:=Me.txt_pass.Value, LookIn:=xlFormulas)
If Not info Is Nothing Then
info.Parent.Activate
info.Offset(0, 1).Select
NUser = ActiveCell.Text
MsgBox "That data was sent"
Else
MsgBox "That data was not found."
End If
'===========(( below code i want to recall it in body of the email ))
With cdomsg
.To = info
.From = "dash32762@gmail.com"
.Subject = "Restore information"
.TextBody = Hello youur username is NUser your password is NPass
.send
End With
Set cdomsg = Nothing
End Function
这是我要为此修改的以下代码
' ========(( below is the code i want to find and store user and pass ))
Set info = Worksheets("AdminPanel2").Range("I11:I80").Find( _
What:=Me.txt_pass.Value, LookIn:=xlFormulas)
If Not info Is Nothing Then
info.Parent.Activate
info.Offset(0, 1).Select
NUser = ActiveCell.Text
MsgBox "That data was sent"
Else
MsgBox "That data was not found."
End If
答案 0 :(得分:2)
在一封电子邮件中发送电子邮件和密码非常糟糕。将电子邮件和密码保存在隐藏的Excel工作表中,更糟。这实际上不是怎么做的,如果这不是学校的项目,那么您可能会遇到很多工作上的问题。最佳做法不是保留密码,而是保留its hash。而不是发送旧密码,而是输入一个新密码。
上面已经说完了,.TextBody
应该是这样的字符串,在变量之间使用&
:
With cdomsg
.To = info
.From = "dash32762@gmail.com"
.Subject = "Restore information"
.TextBody = "Hello your username is" & NUser & " your password is" & NPass
.Send
End With
关于您的问题部分:
With Worksheets("AdminPanel2").Range("I11:I80")
Set info = .Find(What:=Me.txt_pass.Value, LookIn:=xlValues, LookAt:=xlWhole)
End With
If Not info Is Nothing Then
NUser = info.Offset(0, 1)
MsgBox "That data was sent for user " & info
Else
MsgBox "That data was not found."
End If