如何使用vb.net从Windows应用发送电子邮件 [英] How to send email from windows applcation using vb.net

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

问题描述

我是tryig编写了一个简单的例程,以从桌面应用程序发送电子邮件.
为简单起见,我有一个带有一个按钮的表单.该代码是硬编码的,但是我以后可以添加一些提示.当我运行它时,它会调试OK,但是会出现错误无法连接到远程服务器".非常感谢您的帮助.


U am tryig to write simple routine to send email from desktop appliation.
For simplicity I have a form with one button. The code is hardcoded but I can add the bells and whistles later. When I run it it debugs OK but comes up with an error "uable to connect to remote server" Any help will be much appreciated.


Imports System.Net.Mail
Imports System.Net

Public Class Form1


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim mFrom, mTo As String
        mFrom = "hostemailaddress@yahoo.co.uk"
        mTo = "targetemailaddress@yahoo.com"
        Dim mPort As Int32
        mPort = 25      'default port for mail server

        Dim email As New MailMessage(mFrom, mTo)
        email.Subject = "Test Subject"        
        email.Body = Hello World
        Dim mySmtpClient As New SmtpClient("yahoo.co.uk", mPort)
        mySmtpClient.UseDefaultCredentials = True

        Dim emailAdr As String
        Dim passwrd As String

        emailAdr = "hostemailaddress@yahoo.co.uk"
        passwrd = "password"
        mySmtpClient.Credentials = New NetworkCredential(emailAdr, passwrd)
        mySmtpClient.Send(email)

        
    End Sub

End Class

推荐答案

您设置了错误的端口号:Yahoo使用的是端口587,而不是25.
此外,主机应为smtp.yahoo.co.uk:
You set the wrong port number: Yahoo uses port 587, not 25.
Furthermore, the host should be smtp.yahoo.co.uk:
Dim mySmtpClient As New SmtpClient("smtp.yahoo.co.uk", mPort)


感谢您的回复,但仍然无法正常工作.
Thank you for the reply, but it still doesn''t work.


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

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