以视觉血管发送电子邮件 [英] Send emails in visual vasic

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

问题描述

我已经制作了一个表单,我想用它发送电子邮件,我有名称主题电子邮件和密码但它不会发送...任何人都可以帮助告诉我为什么?所有我得到的是'发送消息失败'

*(在代码中我删除了电子邮件并将其更改为示例,当我测试时它不像那样*

抱歉这是一条很长的消息DX



I have made a form and I want to send emails with it, I have name subject email and password but it wont send... could anyone help tell me why? all I get is 'Failed to send message'
*(in the code I have removed the emails and changed them to example it was not like that when I was testing*
sorry this is a long message DX

Dim OMail As New MailMessage()
        Dim oServer As New SmtpClient
        Dim name As String
        Dim theCredential As System.Net.NetworkCredential = New System.Net.NetworkCredential(Email.Text, Password.Text)
        oServer.Credentials = theCredential
        name = FName.Text + Lname.Text

        ' Set recipient email address, please change it to yours
        OMail.From = New MailAddress(Email.Text)

        ' Set recipient email address, please change it to yours
        OMail.To.Add("Example@outlook.com")

        ' Set email subject
        OMail.Subject = Subject.Text

        ' Set email body
        OMail.Body = Template.Text + Message.Text + "This message was sent by " + name + " @ " + Email.Text

        ' Your Office 365 SMTP server address, 
        ' You should get it from outlook web access.
        oServer.Host = "smpt.live.com"

        ' user authentication should use your 
        'Email address as the user name. 
        oServer.Credentials = New Net.NetworkCredential(My.Settings.Email, My.Settings.Emailpass)

        ' Set 587 port
        oServer.Port = 587

        Try
            strMsg = "start to send Feedback..." & vbCrLf & "Please wait"
            strTitle = "Sending Email"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbInformation, strTitle)
            '
            oServer.Send(OMail)
            '
            strMsg = "email was sent successfully!" & vbCrLf & "If a reply is needed you sould get one in the next few days!"
            strTitle = "Email sent"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbInformation, strTitle)

        Catch ex As Exception

            strMsg = "failed to send email with the following error:" & vbCrLf & vbCrLf & "'" & ex.Message & "'"
            strTitle = "Critical Error Encountered"
            Ret_type = MsgBox(strMsg, vbOKOnly + vbCritical, strTitle)
        End Try





我尝试了什么:



我已经尝试了其他人的代码,但是没有人做到这一点,所以我认为这是我最好的选择。



What I have tried:

I have tried other peoples code, but none got as far as this one did so I think this is my best bet.

推荐答案

您应该学习尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到有一点它会停止你所期望的。

在Visual Studio 2010中掌握调试 - 初学者指南 [ ^ ]

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]



使用调试器查看WHERE是错误并查看确切的错误消息。
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]

Use the debugger to see WHERE is the error and to see what is the exact error message.


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

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