如何使用VB.NET通过本地IIS服务器发送邮件 [英] How do I send mail through my local IIS server using VB.NET

查看:115
本文介绍了如何使用VB.NET通过本地IIS服务器发送邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用visual studio 2013发送电子邮件时它可以工作,但相同的代码在visual studio 2015中不起作用。



请帮助!

我也尝试更改端口号但不起作用。

任何将被赞赏,在此先感谢



我尝试过:



Dim s As String

s = vbNewLine

Dim targetURL作为字符串

targetURL =http://xyz.aspx

Dim client As New SmtpClient()

client.Host =abc .mail.com

Dim sendTo As New MailAddress(wer.mail.com)

Dim from As MailAddress = New MailAddress(qwe.mail.com )

Dim message As New MailMessage(from,sendTo)

message.IsBodyHtml = True

message.Subject =Rejoining Approval

'message.SubjectEncoding

昏暗的身体作为字符串



body =尊敬的爵士& vbCrLf&

我想通知你&空间(2)& & cmbdropdownlist.Text& &空间(2)& 已被辞退&空间(2)& & cmbUnit.Text& & vbCrLf&

并希望重新加入& vbCrLf&

所以,请通过以下链接对其采取适当的行动。 &安培; vbCrLf&

& targetURL& & vbCrLf&

谢谢与问候& vbCrLf&

HRD

message.Body = body

'在app.config中使用相同的帐户进行身份验证。

client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network

Dim basicAuthenticationInfo As New System.Net.NetworkCredential(qwe.mail.com,erty)

client.UseDefaultCredentials = False

client.Credentials = basicAuthenticationInfo

client.Port = 25



client.EnableSsl = True



'尝试

client.Send(消息)

MsgBox( 重新加入信息已成功发送给高级,MsgBoxStyle.Information)

When i send email using visual studio 2013 it works but the same code does not work in visual studio 2015.

Please Help !
I have also tried to change port no but doesn't work.
Any will be Appreciated, Thanks In Advance

What I have tried:

Dim s As String
s = vbNewLine
Dim targetURL As String
targetURL = "http://xyz.aspx"
Dim client As New SmtpClient()
client.Host = "abc.mail.com"
Dim sendTo As New MailAddress("wer.mail.com")
Dim from As MailAddress = New MailAddress("qwe.mail.com")
Dim message As New MailMessage(from, sendTo)
message.IsBodyHtml = True
message.Subject = "Rejoining Approval"
' message.SubjectEncoding
Dim body As String

body = "Respected Sir" & vbCrLf &
"I would like to inform you that" & Space(2) & "" & cmbdropdownlist.Text & "" & Space(2) & "has been resigned from" & Space(2) & "" & cmbUnit.Text & "" & vbCrLf &
"and wants to rejoin" & vbCrLf &
"So,Kindly take proper action on it with this given below Link." & vbCrLf &
"" & targetURL & "" & vbCrLf &
"Thanks & Regards" & vbCrLf &
" HRD "
message.Body = body
' Use the same account in app.config to authenticate.
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("qwe.mail.com", "erty")
client.UseDefaultCredentials = False
client.Credentials = basicAuthenticationInfo
client.Port = 25

client.EnableSsl = True

'Try
client.Send(message)
MsgBox("Rejoining Info has been send successfully to Senior", MsgBoxStyle.Information)

推荐答案

这些是SMTP编程中的一般性问题,不仅仅是在.NET框架中,而是几乎在每个平台上,因为服务器需要我们的东西,我们不提供这些内容苦恼的。需要考虑的一些事项是确保将SMTP服务器配置为接受从控制面板发送电子邮件的请求。您应该使用任何提供程序(例如Gmail或Outlook)尝试以下代码,并查看它们是否正常工作。

These are a bit general problems in SMTP programming, not just in .NET framework but almost in every platform because the server requires something out of us, and we are not providing those content details. A few things to consider are to make sure that your SMTP server is configured to accept the requests to send email from control panel. You should try the following code with any of the provider, such as Gmail or Outlook and see if they work correctly.
' You should use a using statement
Using client As New SmtpClient("<smtp-server-address>", 25)
	' Configure the client
	client.EnableSsl = True
	client.Credentials = New NetworkCredential("<username>", "<password>")
	' client.UseDefaultCredentials = true;

	' A client has been created, now you need to create a MailMessage object
	' From field
	' Recipient field
	' Subject of the email message
		' Email message body
	Dim message As New MailMessage("from@example.com", "to@example.com", "Hello", "World!")

	' Send the message
	client.Send(message)

	' 
'    * Since I was using Console app, that is why I am able to use the Console
'    * object, your framework would have different ones. 
'    * There is actually no need for these following lines, you can ignore them
'    * if you want to. SMTP protocol would still send the email of yours. 


	' Print a notification message
	Console.WriteLine("Email has been sent.")
	' Just for the sake of pausing the application
	Console.Read()
End Using

'=======================================================
'Service provided by Telerik (www.telerik.com)
'Conversion powered by NRefactory.
'Twitter: @telerik
'Facebook: facebook.com/telerik
'=======================================================



代码被捕获并从我的文章转换而来,通过.NET框架发送电子邮件,以及一般问题 - 使用C#代码 [ ^ ]在文章的最后我讨论了一些问题,发送邮件失败就是其中之一。在您的代码中,我看到没有问题:1)主机名中没有http。 2)使用25端口。 3)用户名/密码设置。



问题应该在服务器上,检查是否允许您发送电子邮件;它将在SMTP服务器的控制面板下。否则,为任何其他提供程序尝试相同的VB.NET代码; Gmail,Outlook并查看结果。


The code was captured and converted from my article, Sending emails over .NET framework, and general problems – using C# code[^] and at the end of that article I talk about a few problems and "Failure sending mail" is one of them. In your code, I see no problem: 1) No http in hostname. 2) 25 port used. 3) username/password set.

The problem should be on the server, check that you are allowed to send the emails; it would be under the SMTP server's control panel. Otherwise, try the same VB.NET code for any other provider; Gmail, Outlook and see the results.


这篇关于如何使用VB.NET通过本地IIS服务器发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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