邮件功能,可自动发送电子邮件. [英] mailer function which automatically send emails.
本文介绍了邮件功能,可自动发送电子邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要代码如何在asp.net页中添加邮件程序以自动将邮件发送到查询请求表单.
谢谢
Raghav
Hi all,
I need code how to add mailer in an asp.net page to sending mails automatically to as enquiry request form.
Thanks
Raghav
推荐答案
向多个用户发送电子邮件的功能,还需要将代码添加到web.config文件中
Function to send email to multiple users also you need to add code into web.config file
Public Sub SendEmail(ByVal emailAddress As String, ByVal Subject As String, ByVal Body As String)
Dim message As New MailMessage
Dim mf As New MailAddress("syscat@NYCT.com")
'Dim mt As New MailAddress(emailAddress)
Dim emailClient As New SmtpClient
Dim a() As String = emailAddress.Split(";")
Dim i As Integer
Try
For i = 0 To a.Length - 1
If String.IsNullOrEmpty(a(i).ToString) = False Then
message.To.Add(a(i))
End If
Next
message.From = mf
message.IsBodyHtml = True
message.Subject = Subject
message.Body = Body
emailClient.UseDefaultCredentials = True
emailClient.Send(message)
Catch e As Exception
Finally
End Try
End Sub
这是webconfig的代码
Here is code for webconfig
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="youeemail@domain.com">
<network host="192.168.1.1" port="25" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
您可能需要添加用户名nam密码才能使用smtp服务器进行花样
you may need to add user is nam password for anthetication with smtp server
最有效的解决方案是创建一个窗口服务并将其安装在您的服务器上,如果是的话,请检查以下链接,
简单Windows服务示例 [ 在下面查看此链接
使用ASP.NET模拟Windows服务以运行计划的作业 [ http://www.mikesdotnetting.com/Article/129/Simple-task- Scheduling-using-Global.asax [ ^ ]
您可能会发现此链接很有帮助
http://allen-conway-dotnet.blogspot. com/2009/12/running-periodic-process-in-net-using.html [
Most effective solution is to create a window service and install it at your server, if so check this link below,
Simple Windows Service Sample[^]
another solution is use Global.asax Application_OnStart, so that, as long as the web app is running, your "scheduler" is guaranteed to be running too.
check this link below
Simulate a Windows Service using ASP.NET to run scheduled jobs[^]
http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax[^]
you may find this link helpful
http://allen-conway-dotnet.blogspot.com/2009/12/running-periodic-process-in-net-using.html[^]
这篇关于邮件功能,可自动发送电子邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文