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

Problems Sending Email with VB.NET ASP.NET

P: 88
I'm trying to send a notification from my application and I get no errors, but never recieve the email message. Here is my code in my .vb file;

Expand|Select|Wrap|Line Numbers
  1. Imports System.Net.Mail
  2. Partial Class Subscribe
  3.     Inherits System.Web.UI.Page
  4.     Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
  5.         If Page.IsValid Then
  6.             Dim Client As System.Net.Mail.SmtpClient
  7.             Dim Mailmsg As New System.Net.Mail.MailMessage
  8.             'Prepare Email to Website Administrator
  9.             Mailmsg.To.Add(New MailAddress("email@something.com"))
  10.             Mailmsg.Subject = "New Website Subscription Request."
  11.             Mailmsg.From = New MailAddress(Email.Text)
  12.             Mailmsg.IsBodyHtml = True
  13.             Mailmsg.Priority = MailPriority.High
  14.             Mailmsg.Body = "<html><body><b>Subscription Request</b><br /><br />Name: " & Name.Text & "<br />Title: " & Title1.Text & "<br />"
  15.             Client = New System.Net.Mail.SmtpClient
  16.             Client.Send(Mailmsg)
  17.             Server.Transfer("Subscribe_Confirm.aspx")
  18.         End If
  19.     End Sub   
  20. End Class
This is in my web.config file:


Expand|Select|Wrap|Line Numbers
  1. </system.web>
  2.   <system.net>
  3.     <mailSettings>
  4.       <smtp from="email@somthing.com">
  5.         <network host="server" port="port" userName="username" password="password" defaultCredentials="true" />
  6.       </smtp>
  7.     </mailSettings>    
  8.   </system.net>
Of course I have the email, host, port, username & password filled in with the real values, I just replaced them here.

Thanks
Jan 9 '08 #1
Share this Question
Share on Google+
1 Reply


P: 24
Hi fperri,

I'm not a programming expert so I can't comment on the code, but I have done my share of troubleshooting email servers. One of the most common problems I see is the relay settings on the SMTP service. Make sure that your mail server allows relaying from the server that runs the web application. To verify this, start a command prompt and type the follwoing commands (lines 1,3,5,7,9,11-13 are what you type, and the rest are the expected responses):

Expand|Select|Wrap|Line Numbers
  1. C:\>telnet mailserver.example.com 25
  2. 220 example.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at  Mon, 14 Jan 2008 19:40:43 -0500
  3. helo
  4. 250 example.com Hello [192.168.30.17]
  5. mail from:<jens@example.com>
  6. 250 2.1.0 jens@example.com....Sender OK
  7. rcpt to:<jens@remote-domain.com>
  8. 250 2.1.5 jens@remote-domain.com
  9. data
  10. 354 Start mail input; end with <CRLF>.<CRLF>
  11. Subject:Test
  12. This is a test.
  13. .
  14. 250 2.6.0 <NEONjKtfB37vfFx38Pe00000001@example.com> Queued mail for delivery
  15.  
If you get any errors here, then you should probably troubleshoot these before you look deeper into your code.

Hope that helps!

JE
Jan 15 '08 #2

Post your reply

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