|
-
Jun 16th, 2010, 06:29 AM
#1
Thread Starter
Frenzied Member
Problem sending emails
Hi Peeps,
I am having a problem sending emails from my website. Intially I was putting the settings in the web.config file and then changed to code but it is still looking in the web.config file; why? Here is my code for sending an email:-
Code:
Dim member As MembershipUser = Membership.GetUser(User.Identity.Name)
Dim sEmailAddress As String = member.Email.ToString
Dim mmEMail As New MailMessage(rppGlobals.FromEmailAddress, sEmailAddress)
Dim smtp As New SmtpClient
Dim sBody As String
Dim Attach As New System.Net.Mail.Attachment(Server.MapPath("") & "\CSVFiles\" & sFilename)
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("Username", "Password", "Domain")
mmEMail.Subject = sFilename
mmEMail.Attachments.Add(Attach)
sBody = ""
mmEMail.Body = sBody
smtp.Host = "host.address.0.0"
smtp.Port = 0
smtp.UseDefaultCredentials = False
smtp.Credentials = basicAuthenticationInfo
smtp.Send(mmEMail)
mmEMail.Dispose()
Any ideas please,
Jiggy!
-
Jun 16th, 2010, 08:11 AM
#2
Re: Problem sending emails
If you are not using the setting in your web.config file, why are they still there. Either take them out, or comment then out.
Have you tried stepping through your code? Does it actually get executed?
If you are getting an error, what is it?
Gary
-
Jun 16th, 2010, 08:25 AM
#3
Thread Starter
Frenzied Member
Re: Problem sending emails
Hi Gary,
If I comment them out in the web.config file it says smtp host is not set?
Thanks for the reply
Jiggy!
-
Jun 16th, 2010, 08:25 AM
#4
Re: Problem sending emails
 Originally Posted by Jigabyte
Hi Peeps,
I am having a problem sending emails from my website. Intially I was putting the settings in the web.config file and then changed to code but it is still looking in the web.config file; why? Here is my code for sending an email:-
Code:
Dim member As MembershipUser = Membership.GetUser(User.Identity.Name)
Dim sEmailAddress As String = member.Email.ToString
Dim mmEMail As New MailMessage(rppGlobals.FromEmailAddress, sEmailAddress)
Dim smtp As New SmtpClient
Dim sBody As String
Dim Attach As New System.Net.Mail.Attachment(Server.MapPath("") & "\CSVFiles\" & sFilename)
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("Username", "Password", "Domain")
mmEMail.Subject = sFilename
mmEMail.Attachments.Add(Attach)
sBody = ""
mmEMail.Body = sBody
smtp.Host = "host.address.0.0"
smtp.Port = 0
smtp.UseDefaultCredentials = False
smtp.Credentials = basicAuthenticationInfo
smtp.Send(mmEMail)
mmEMail.Dispose()
Any ideas please,
Jiggy!
You didn't mention the problem. What setting its retrieving from webconfig file
What about this line
Code:
Dim mmEMail As New MailMessage(rppGlobals.FromEmailAddress, sEmailAddress)
What is rppGlobals ?
Please mark you thread resolved using the Thread Tools as shown
-
Jun 16th, 2010, 08:26 AM
#5
Thread Starter
Frenzied Member
Re: Problem sending emails
The rppGlobals is my own class that has the from email address set.
-
Jun 16th, 2010, 08:29 AM
#6
Re: Problem sending emails
 Originally Posted by Jigabyte
The rppGlobals is my own class that has the from email address set.
Are you reading from web.config file?
Please mark you thread resolved using the Thread Tools as shown
-
Jun 16th, 2010, 08:29 AM
#7
Thread Starter
Frenzied Member
Re: Problem sending emails
The exact error message I get if I comment out the information in the web.config file is:-
The SMTP host was not specified.
-
Jun 16th, 2010, 08:30 AM
#8
Thread Starter
Frenzied Member
Re: Problem sending emails
This was my first problem. I wanted to set it in code so I commented it out in the web.config file but then I get the above error message as if it's looking in the web.config.
-
Jun 16th, 2010, 08:38 AM
#9
Re: Problem sending emails
Did you set a breakpoint on this line:
Code:
smtp.Host = "host.address.0.0"
Does it get hit?
Also, what is that? It don't look like any host that I have ever seen?!?
Gary
-
Jun 16th, 2010, 08:41 AM
#10
Thread Starter
Frenzied Member
Re: Problem sending emails
I am running it from the server end and its a made up one. I do have a valid one there.
-
Jun 16th, 2010, 08:41 AM
#11
Re: Problem sending emails
Debug the code and check the host in this line
Please mark you thread resolved using the Thread Tools as shown
-
Jun 16th, 2010, 08:49 AM
#12
Thread Starter
Frenzied Member
Re: Problem sending emails
Sorry I am publishing it to the site and testing it there. I put these lines of code in after the smtp.host assignment and it showed the correct host.
Code:
label1.text = smtp.host.tostring
exit sub
-
Jun 16th, 2010, 09:08 AM
#13
Re: Problem sending emails
So, are you saying that the code works without throwing any errors, it just that you aren't getting the email?
I am confused.
Gary
-
Jun 16th, 2010, 09:14 AM
#14
Thread Starter
Frenzied Member
Re: Problem sending emails
Sorry; when I comment out the web.config settings I get the error host not specified but when I put the line of code in above to show that smtp.host is set. If I remove that and let you complete I get the error message smtp.host not specified. If I uncomment the web.config settings I get a different error which indicates it is ignoring what I am setting in code.
-
Jun 16th, 2010, 09:31 AM
#15
Re: Problem sending emails
May be you have deployed the old files, Recompile your project and deploy new files..
or restart the IIS and try
Please mark you thread resolved using the Thread Tools as shown
-
Jun 16th, 2010, 09:33 AM
#16
Thread Starter
Frenzied Member
Re: Problem sending emails
I do a build locally and ftp the files up and they all have the correct date/time. To me it is ignoring my settings and looking for them in the web.config file?
-
Jun 16th, 2010, 09:42 AM
#17
Thread Starter
Frenzied Member
Re: Problem sending emails
Okay I have put all entries now in the web.config file because I assume that is where they need to be but now I get the following error which was what I was getting write from the start:-
Code:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Thanks for any advice,
Jiggy!
-
Jun 16th, 2010, 12:00 PM
#18
Re: Problem sending emails
Ok, first of all, you can definitely do everything in code, you don't need to do it in the web.config.
Secondly, have you verified that all the settings that you are using for sending the email are correct, i.e. the username and password, the host address, etc?
For instance, can you put all the details into something like google mail, as a new account, and send and receive successfully?
Gary
-
Jun 16th, 2010, 12:21 PM
#19
Thread Starter
Frenzied Member
Re: Problem sending emails
Hi Gary;
I have spoken with your network IT guy and he says that it needs to us smtp authentication and connect using the username and password. If I removie everything from the web.config file and set it all in code it says no host specified so I have put the same in the config file.
Thanks,
Jiggy!
-
Jun 17th, 2010, 01:16 AM
#20
Re: Problem sending emails
Hey,
Okay, by means of a walk through, can you try the following:
http://weblogs.asp.net/scottgu/archi...10/432854.aspx
If that doesn't work, can you try a new project, without anything in the web.config file, and try sending the email using the server side code. At the end of the day, short of enabling SSL (which I have never been able to find a way to do using the web.config file), you should be able to send emails using both methods.
Did you verify that you are able to send/receive emails using the settings that you have through a third party application?
Gary
-
Jun 17th, 2010, 04:44 AM
#21
Thread Starter
Frenzied Member
Re: Problem sending emails
Hi Gary,
First off thank you for getting back to me. I created a blank web project and add the code to a button click. I tried it we my domain (O2) which also requires a username and password and that works fine but it does not work for the domain I need it to work on. I was told the username and password had to be base64 so I converted them but still this error:-
Code:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
This is really getting on my nerves now; I have spent almost a week on it and still no joy. Is there something I can run like a tracer to see the communication between my email request and the exchange server?
Thanks again for you help,
Jiggy!
-
Jun 17th, 2010, 05:57 AM
#22
Re: Problem sending emails
Okay, so to confirm, your latest test was done using only the code, nothing in the web.config file, correct?
So the problem with the host has gone, correct?
This really sounds like this is an issue with the domain/credentials that you are trying to use to send the email. If it works for one domain, and not the other, then the code works.
Sending email through SMTP has historically been difficult, and at the mercy of the SMTP Server settings, which are different for everyone.
Gary
-
Jun 17th, 2010, 06:01 AM
#23
Thread Starter
Frenzied Member
Re: Problem sending emails
Hi Gary,
Yes all works for my domain but not for the other domain. I really can't understand why. I can telnet to the server with the port number but can't send emails.
-
Jun 17th, 2010, 06:02 AM
#24
Thread Starter
Frenzied Member
Re: Problem sending emails
This is the stack trace I get:-
Code:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +239
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +35
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +224
[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +5483819
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +202
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +332
System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +160
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +159
System.Net.Mail.SmtpClient.GetConnection() +35
System.Net.Mail.SmtpClient.Send(MailMessage message) +1213
[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1531
_Default.Button1_Click(Object sender, EventArgs e) +238
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
-
Jun 17th, 2010, 06:31 AM
#25
Re: Problem sending emails
Okay, just to clarify a couple of things...
Earlier you mentioned that you were using remote servers. In the test that you are doing now, are you both telnet'ing and running the application from the same server? i.e. I want to rule out the possibility that you have some sort of firewall in place that is stopping the communication.
With the exception of the exact credentials, and IP address etc, can you show the exact code that you are currently testing?
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|