电子邮件发送端口号问题 [英] email sending port number problem

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

问题描述

在vb.net发送电子邮件。



我收到以下错误,在事件视图中可以看到。



请帮助...





功能/模块名称:ProcessMail-Process fax System.ArgumentOutOfRangeException:指定的参数已经输出有效值范围。参数名称:ImpsFaxService.ProcessFax.SendMail1的System.Net.Mail.SmtpClient.set_Port(Int32值)的值(字符串& To,String& From,String& Subject,String& Body,String& Bcc,ArrayList& Attachment,Boolean& ; IsBodyHtml,String& SMTPServer)在H:\ PROJECTS \Fax_Service_28_2_2014 \ ProcessFaxOCR.vb:第1264行



192.168.10.5是可选的smtp服务器。我正在使用另一个端口号为587的smtp服务器。



它在Windows 7中运行良好但在Windows Server 2008 R2中出错。




公共函数SendMail1(ByRef [To] As String,ByRef From As String,_

ByRef Subject As String,ByRef Body As字符串,_

可选ByRef Bcc As String = Nothing,_

可选ByRef附件As ArrayList = Nothing,_

可选ByRef IsBodyHtml As Boolean = True,_

可选ByRef SMTPServer As String =192.168.10.5)As Boolean



Dim iFileCount As Integer

'将发送邮件的变量

Dim obj As System.Net.Mail.SmtpClient



'变量创建消息给s结束

Dim Mailmsg As New System.Net.Mail.MailMessage()

尝试

'设置属性

'分配SMTP服务器

obj =新的System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings(SMTPServer))

obj .Port = System.Configuration.ConfigurationManager.AppSettings(Port)

'可以使用多个接收者指定;作为分隔符



'收件人地址

Mailmsg.To.Add([To])

'你的发件人地址

'您还可以使用自定义标题回复来获取不同的回复地址

Mailmsg.From =新的System.Net.Mail.MailAddress(来自)

'指定正文格式

如果IsBodyHtml = True则

Mailmsg.IsBodyHtml = IsBodyHtml'以HTML格式发送邮件
Else

Mailmsg.IsBodyHtml = IsBodyHtml

结束如果



'邮件主题

Mailmsg.Subject =主题



'逐个附加文件

如果不是IsNothing(附件)那么

对于iFileCount = 0到Attachment.Count - 1

'添加附件到th电子邮件

Mailmsg.Attachments.Add(New Net.Mail.Attachment(Attachment.Item(iFileCount).ToString))

下一页

结束如果

'邮件正文

Mailmsg.Body =正文

'---网络凭证

Dim basicAuthenticationInfo As New System.Net.NetworkCredential()'username,password)

basicAuthenticationInfo.UserName = ObjCrypto.Decrypt(System.Configuration.ConfigurationManager.AppSettings(Username))

basicAuthenticationInfo.Password = ObjCrypto.Decrypt(System.Configuration.ConfigurationManager.AppSettings(Password))



'我们的ISp邮件服务器或本地主机。



obj.UseDefaultCredentials = False

'在此设置凭据,其中用户名nad密码用于通过应用程序访问邮件服务器/>
obj.Credentials = basicAuthenticationInfo



'调用send方法发送邮件

obj.Send(Mailmsg)



Catch ex As Exception

mobjLogErr.LogError(LogError.ErrorLog.EVENTLOG,ex.ToString,ProcessMail-Process fax)

最后

如果不是IsNothing(Mailmsg)那么Mailmsg = Nothing

结束尝试



结束函数

Email sending in vb.net.

I got below error , which is seen in event view.

please help...


Function/Module Name : ProcessMail-Process fax System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value at System.Net.Mail.SmtpClient.set_Port(Int32 value) at ImpsFaxService.ProcessFax.SendMail1(String& To, String& From, String& Subject, String& Body, String& Bcc, ArrayList& Attachment, Boolean& IsBodyHtml, String& SMTPServer) in H:\PROJECTS\Fax_Service_28_2_2014\ProcessFaxOCR.vb:line 1264

192.168.10.5 is optional smtp server . i am using another smtp server with port no 587.

It is working well in windows 7 but gives error in windows server 2008 R2.


Public Function SendMail1(ByRef [To] As String, ByRef From As String, _
ByRef Subject As String, ByRef Body As String, _
Optional ByRef Bcc As String = Nothing, _
Optional ByRef Attachment As ArrayList = Nothing, _
Optional ByRef IsBodyHtml As Boolean = True, _
Optional ByRef SMTPServer As String = "192.168.10.5") As Boolean

Dim iFileCount As Integer
' Variable which will send the mail
Dim obj As System.Net.Mail.SmtpClient

'Variable to create the message to send
Dim Mailmsg As New System.Net.Mail.MailMessage()
Try
'Set the properties
'Assign the SMTP server
obj = New System.Net.Mail.SmtpClient(System.Configuration.ConfigurationManager.AppSettings("SMTPServer"))
obj.Port = System.Configuration.ConfigurationManager.AppSettings("Port")
'Multiple recepients can be specified using ; as the delimeter

'Address of the recipient
Mailmsg.To.Add([To])
'Your From Address
'You can also use a custom header Reply-To for a different replyto address
Mailmsg.From = New System.Net.Mail.MailAddress(From)
'Specify the body format
If IsBodyHtml = True Then
Mailmsg.IsBodyHtml = IsBodyHtml 'Send the mail in HTML Format
Else
Mailmsg.IsBodyHtml = IsBodyHtml
End If

'Mail Subject
Mailmsg.Subject = Subject

'Attach the files one by one
If Not IsNothing(Attachment) Then
For iFileCount = 0 To Attachment.Count - 1
'Adds attachments to the mail
Mailmsg.Attachments.Add(New Net.Mail.Attachment(Attachment.Item(iFileCount).ToString))
Next
End If
'Mail Body
Mailmsg.Body = Body
'---Network Credentials
Dim basicAuthenticationInfo As New System.Net.NetworkCredential() '"username", "password")
basicAuthenticationInfo.UserName = ObjCrypto.Decrypt(System.Configuration.ConfigurationManager.AppSettings("Username"))
basicAuthenticationInfo.Password = ObjCrypto.Decrypt(System.Configuration.ConfigurationManager.AppSettings("Password"))

'Our ISp mail server or Local host.

obj.UseDefaultCredentials = False
'set the Credentials here in which user name nad password for accessing the mail server through application
obj.Credentials = basicAuthenticationInfo

'Call the send method to send the mail
obj.Send(Mailmsg)

Catch ex As Exception
mobjLogErr.LogError(LogError.ErrorLog.EVENTLOG, ex.ToString, "ProcessMail-Process fax")
Finally
If Not IsNothing(Mailmsg) Then Mailmsg = Nothing
End Try

End Function

推荐答案

确保配置文件包含端口的有效条目。如果该条目不存在,您的代码可能会将值设置为0,这是无效的。还要检查其他无效的条目(非数字或大或负的数字......)。
Make sure that the config file contains a valid entry for the Port. If the entry is not present, your code may set the value to 0, which is not valid. Also check for other non-valid entries (non-numeric, or numbers which are to big or negative...).


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

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