Email will not send my visual studio 2003 project
-
Email will not send my visual studio 2003 project 1. I am using MSDE, IIS, Visual studio 2003, 1.1 netframework, I have mail Outlook and msn homail, 2. these are installed on windows xp 3. Can I send email if I only have msde and not a regular server? 4. The project works except the sending of the email 5. I thought I have coded below correctly, but I do not receive emails Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started '1. Create a connection Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString")) myConnection.Open() '2. Create the command object, for the query Const strSQL As String = "Select LastUpdated, ProductId from products " Dim objCmd As New SqlCommand(strSQL, myConnection) Dim objDR As SqlDataReader Dim att objDR = objCmd.ExecuteReader() While (objDR.Read) If (Not (objDR("LastUpdated") Is DBNull.Value)) Then If (Date.Compare(objDR("LastUpdated"), Today.Date) = 0) Then Dim newMail As New MailMessage newMail.From = "from@from.com" '' this is the From Address newMail.To = "kenn_rosie@msn.com" '' this is TO Address 'newMail.Cc = "hadeedian@hotmail.com" '' this is TO Address newMail.Subject = "Change in Product Rate" newMail.Body = " Dear Ken, " & "Please review attached email for product ID: " & objDR("ProductID") & "Thank you," & "Kenn()" att = New MailAttachment("C:\Inetpub\wwwroot\GrocerToGo\Product_Changed.doc") newMail.Attachments.Add(att) newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username") newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password") SmtpMail.SmtpServer = "mailserver" SmtpMail.Send(newMail) End If End If End While myConnection.Close() 'Close the connection End Sub
-
Email will not send my visual studio 2003 project 1. I am using MSDE, IIS, Visual studio 2003, 1.1 netframework, I have mail Outlook and msn homail, 2. these are installed on windows xp 3. Can I send email if I only have msde and not a regular server? 4. The project works except the sending of the email 5. I thought I have coded below correctly, but I do not receive emails Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started '1. Create a connection Dim myConnection As New SqlConnection(ConfigurationSettings.AppSettings("connectionString")) myConnection.Open() '2. Create the command object, for the query Const strSQL As String = "Select LastUpdated, ProductId from products " Dim objCmd As New SqlCommand(strSQL, myConnection) Dim objDR As SqlDataReader Dim att objDR = objCmd.ExecuteReader() While (objDR.Read) If (Not (objDR("LastUpdated") Is DBNull.Value)) Then If (Date.Compare(objDR("LastUpdated"), Today.Date) = 0) Then Dim newMail As New MailMessage newMail.From = "from@from.com" '' this is the From Address newMail.To = "kenn_rosie@msn.com" '' this is TO Address 'newMail.Cc = "hadeedian@hotmail.com" '' this is TO Address newMail.Subject = "Change in Product Rate" newMail.Body = " Dear Ken, " & "Please review attached email for product ID: " & objDR("ProductID") & "Thank you," & "Kenn()" att = New MailAttachment("C:\Inetpub\wwwroot\GrocerToGo\Product_Changed.doc") newMail.Attachments.Add(att) newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1") newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username") newMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password") SmtpMail.SmtpServer = "mailserver" SmtpMail.Send(newMail) End If End If End While myConnection.Close() 'Close the connection End Sub
A few things to check... Try to sent an email from the command line via telnet, this is email in it's simplest form to comfirm that port 25 and the SMTP server are OK. http://www.yuki-onna.co.uk/email/smtp.html[^] If this works great if not check you don't have port filtering or antivirus stopping your mail app. McAfee has a "unwanted apps filter" as some of the others do and this treats port 25 bound apps as mail worms, (This caught me out on my app). Hope this helps, let me know... P.S. Code looks OK will try it and see.:) When people make you see red, be thankful your not colour blind. -- modified at 19:45 Wednesday 22nd February, 2006
-
A few things to check... Try to sent an email from the command line via telnet, this is email in it's simplest form to comfirm that port 25 and the SMTP server are OK. http://www.yuki-onna.co.uk/email/smtp.html[^] If this works great if not check you don't have port filtering or antivirus stopping your mail app. McAfee has a "unwanted apps filter" as some of the others do and this treats port 25 bound apps as mail worms, (This caught me out on my app). Hope this helps, let me know... P.S. Code looks OK will try it and see.:) When people make you see red, be thankful your not colour blind. -- modified at 19:45 Wednesday 22nd February, 2006
OK Tested the email portion of your code... Imports System.Web.mail
Dim newMail As New MailMessage Dim SmtpSvr As SmtpMail Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub mySendMail() SmtpMail.SmtpServer = "127.0.0.1" newMail.To = "kne@canon.com.au" '' this is TO Address newMail.From = "japel-xp@localhost" '' this is the From Address newMail.Subject = "Change in Product Rate" newMail.Body = "Dear Ken" SmtpMail.Send(newMail) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click mySendMail() End Sub
Added the (Dim SmtpSvr As SmtpMail) and the rest worked. Please let me know how you go... Also catch the email Exception by putting your code in a try/catch the below will tell you the return smtp server error e.g. 550 No Realy...Catch ex As Exception MessageBox.Show(ex.GetBaseException.Message) End Try
When people make you see red, be thankful your not colour blind.