Click here to Skip to main content
15,946,158 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Email sending in

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 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 = "") 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()
'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
'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
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))
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

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

End Function
Updated 4-Mar-14 19:51pm
[no name] 5-Mar-14 0:59am    
Please provide your code.
Krunal Rohit 5-Mar-14 1:03am    
Paste your.entire code.

Aravindba 5-Mar-14 2:19am    
try to enable SMTP in windows server 2008 R2,disable windows firewall,antivirus firewall

1 solution

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...).
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900