Vb.net不发送电子邮件 [英] Vb.net not sending email

查看:90
本文介绍了Vb.net不发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我正在制作的订购系统的一部分,我将有一个忘记密码选项,允许用户选择新密码。程序通过电子邮件向他们发送随机生成的6位数代码,然后用户必须输入该代码。但是,电子邮件没有发送。我使用的代码或多或少与我在早期程序中使用的代码完全相同。



我尝试了什么:



这是到目前为止的代码:

As part of an ordering system I am making, I will have a forgot password option which allows the user to choose a new password. The program emails them a randomly generated 6 digit code which the user then has to input. However, the email is not sending. I have used code which is more or less identical to code I used in an earlier program which worked correctly.

What I have tried:

This is the code so far:

Try
                    Dim array(6) As String
                    Dim rn As New Random
                    Dim digitCode As Integer
                    Randomize()
                    For count = 1 To 6
                        'array(count) = "1"
                        array(count) = rn.Next(0, 9)
                    Next
                    digitCode = array(1) + array(2) + array(3) + array(4) + array(5) + array(6)
                    sixDigitCode = digitCode

                    Dim email As New MailMessage
                    Dim SMTP As New SmtpClient("smtp.gmail.com")
                    email.Subject = "Forgot Password"
                    email.From = New MailAddress("Ordering system prototype")
                    SMTP.Credentials = New System.Net.NetworkCredential("myemailaddress@gmail.com", "mypassword")
                    email.To.Add(EmailAddress)
                    email.Body = SixDigitCode
                    SMTP.EnableSsl = True
                    SMTP.Port = "587"
                    SMTP.Send(email)
                    TabControlForgotPassword.SelectedIndex = 2
                    MsgBox("A six digit code has been sent to" + EmailAddress)

                Catch ex As Exception
                    MsgBox("Could not send email. Contact your Adminiatrator.")
                End Try









我以为可能是因为Google更新了他们的SMTP号码?但是我已经检查过了,我可以确认587是正确的号码。有什么我做错了吗?





I thought it might be due to Google updating their SMTP number? But I have checked and I can confirm that 587 is the correct number still. Is there anything I have done wrong?

推荐答案

将异常错误消息字符串添加到消息框输出中以了解出现了什么问题:

Add the exception error message string to the message box output to know what went wrong:
MsgBox("Could not send email." + ex.Message)



另请注意,您必须允许安全性较低的应用程序为使用过的Goggle邮件帐户发送邮件(请参阅允许或禁止安全性较低的应用访问帐户 - G Suite管理员帮助 [ ^ ])如步骤2 - 使用Gmail SMTP服务器所述从打印机,扫描仪或应用程序发送电子邮件 - G Suite管理员帮助 [ ^ ]。



其他可能的错误来源是阻止请求的防火墙。





并且,同时通过获取错误已知消息,发件人字段不包含有效的电子邮件地址:


Note also that you must allow less secure applications sending mail for the used Goggle mail account (see Allow or disallow less secure apps to access accounts - G Suite Administrator Help[^]) as noted at Step 2 - Use the Gmail SMTP Server at Send email from a printer, scanner, or app - G Suite Administrator Help[^].

Other possible error sources are firewalls blocking the request.


And, as known meanwhile by getting the error message, the 'From' field does not contain a valid email address:

email.From = New MailAddress("Ordering system prototype")



[/ EDIT]


[/EDIT]


这篇关于Vb.net不发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆