By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,637 Members | 1,967 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,637 IT Pros & Developers. It's quick & easy.

smtp server issue

P: 63
Hi Everybody,

i have a problem with smtp server. i developed an application on my local machine and it runs fine.it uses our smtp server to send emails. but when i uploaded the app on to the server it does not send any emails although it is using the same smtp server.

our smtp server settings are definitly not an issue. anonymous access is given there is no limit on number of messages everything is fine.i dont know how is it able to work on local mahcine and not on server(even though both are using same smtp server)

did anyone face this kind of problem. please let me know if you have any ideas

Ayush
Sep 19 '08 #1
Share this Question
Share on Google+
8 Replies


Plater
Expert 5K+
P: 7,872
Have you put in code to see why it is failing?
Sep 19 '08 #2

Frinavale
Expert Mod 5K+
P: 9,731
Make sure there are no Firewalls or Proxies that could be blocking emails.

Check your Windows event logs for any details about what might be failing...

In your code, put try catches in and check if emails were sent success fully...if not then record it into a log so that you can determine what the problem is.

-Frinny
Sep 19 '08 #3

P: 63
Hi all,
thank you for replying.This code worked before. it sent emails but now it suddenly stopped working. there are no major changes we did to server settings. there are no firewalls and proxies. I cannot see anything in smtp log there are no details listed about the mail sent at that time. i tried sending emails from command prompt of that server and the emails went out.so i think this is not a server issue. but the code worked before i dont know whats wrong now. any ideas?

Code:(text)
Expand|Select|Wrap|Line Numbers
  1.  Try
  2.             oEmail.To = recipient
  3.             oEmail.Subject = subject
  4.             oEmail.Body = message
  5.             oEmail.BodyFormat = bodyFormat
  6.             oEmail.From = sender
  7.  
  8.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  9.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = hostSmtpServer
  10.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  11.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "fgtt\ggggg"
  12.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "hghg"
  13.  
  14.             SmtpMail.SmtpServer = hostSmtpServer
  15.             SmtpMail.Send(oEmail)
  16.  
  17.         Catch
  18.         End Try
Sep 22 '08 #4

Frinavale
Expert Mod 5K+
P: 9,731
Record any exceptions you've encountered in your Catch block....you could write it to a text file, record it to an event log....but right now you are catching the exception and not doing anything with it.

You could remove the Try Catch block for testing purposes...when an exception is thrown it should appear in your Windows Application Event Log in this case....
Sep 22 '08 #5

P: 63
i tried catching an exception but there is no exception thrown nor i can see some error in event viewer.

what is strange is i can send the emails from a command prompt from the server that my application is, using smtp server that is sending emails. but when i do the same thing from website it does not happen. so theres definitly something wrong with the code.

Expand|Select|Wrap|Line Numbers
  1. Public Shared Sub SendEmail(ByVal recipient As String, _
  2.                                 ByVal sender As String, _
  3.                                 ByVal subject As String, _
  4.                                 ByVal message As String, _
  5.                                 ByVal hostSmtpServer As String, _
  6.                                 Optional ByVal bodyFormat As MailFormat = MailFormat.Html)
  7.  
  8.         Dim oEmail As New MailMessage
  9.  
  10.         Try
  11.             oEmail.To = recipient
  12.             oEmail.Subject = subject
  13.             oEmail.Body = message
  14.             oEmail.BodyFormat = bodyFormat
  15.             oEmail.From = sender
  16.  
  17.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
  18.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = hostSmtpServer
  19.             oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  20.  
  21.             SmtpMail.SmtpServer = hostSmtpServer
  22.             SmtpMail.Send(oEmail)
  23.  
  24.         Catch Ex As Exception
  25.             Dim objStreamWriter As StreamWriter
  26.             objStreamWriter = File.AppendText("C:\sample.txt")
  27.             objStreamWriter.WriteLine(Ex)
  28.             objStreamWriter.Close()
  29.  
  30.         End Try
  31.  
  32.     End Sub
  33.  
(Hi Frinavale,
please let me know how to add code tags i have no idea how to do that.)


Ayush
Sep 23 '08 #6

Curtis Rutland
Expert 2.5K+
P: 3,256
You can use the # button on the text editor to insert your opening and closing code tags.

It's like HTML with square brackets instead. [code] to open, and you close by putting a slash in between the bracket and the c: [/C
Sep 23 '08 #7

Frinavale
Expert Mod 5K+
P: 9,731
What version of .NET are you using and what namesapce are you using to create your MailMessage?

The only thing that I'm unsure of in your code is the use of the Fields property. Looking up the MailMessage control (in the System.Net.Mail namespace) I don't see a Fields property at all...I've never used this property.

Anyways, give the following code a try and see if it works.
(Please note that right now I'm unable to fully test the code so it may not work 100%)

Expand|Select|Wrap|Line Numbers
  1.  Public Shared sub SendEmail(ByVal recipient As String, _
  2.    ByVal sender As String, _
  3.    ByVal subject As String, _
  4.    ByVal message As String, _
  5.    ByVal hostSmtpServer As String, _
  6.    Optional ByVal bodyFormat As MailFormat = MailFormat.Html)
  7.  
  8.  
  9.  
  10.   Try
  11.   'oEmail.To = recipient
  12.   'oEmail.Subject = subject
  13.   'oEmail.Body = message
  14.   'oEmail.BodyFormat = bodyFormat
  15.   'oEmail.From = sender
  16.  
  17.  'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1
  18.  'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = hostSmtpServer
  19.  'oEmail.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  20. oEmail= New Net.Mail.MailMessage(sender, recipient, subject, message)
  21.  
  22.  
  23. 'SmtpMail.SmtpServer = hostSmtpServer
  24. 'SmtpMail.Send(oEmail)
  25.  
  26. Dim mailClient As New Net.Mail.SmtpClient(hostSmtpServer, 25)
  27. mailClient.Send(oEmail)
  28.  
  29.  Catch Ex As Exception
  30.  Dim objStreamWriter As StreamWriter
  31.  objStreamWriter = File.AppendText("C:\sample.txt")
  32.  objStreamWriter.WriteLine(Ex)
  33.  objStreamWriter.Close()
  34.  
  35.  End Try
  36.  
  37.  End Sub
  38.  
  39.  
Also, does your mail server provider require credentials in order to send emails?

-Frinny
Sep 23 '08 #8

P: 63
Hi,

I am using .NET 1.1 VS 2003. I am using "Imports System.Web.Mail" mail sever does not need credentials . I removed credentials and checked it it still doesn't send any emails.
Sep 23 '08 #9

Post your reply

Sign in to post your reply or Sign up for a free account.