Unable to send email with IIS7 - asp.net

I'm migrating a website from IIS6 to IIS7. I have everything working but the site will not send emails.
I have confirmed that the server is handling emails correctly, because when I drop a text document into the pickup folder it is delivered, but when I try to send a message via code I either get an error or just nothing.
The SMTP virtual server is setup with standard settings.
The website in question is using 4.0 Framework, Integrated Application pool, I've tried both the ApplicationPoolIdentity, and the NetworkService with no effect. For the site's SMTP module I've tried an SMTP server of 127.0.0.1, localhost and the server's domain name, all on port 25.
For testing I've been using VBS and classic asp to send an email as well as asp.net.
I've been trying very basic scripts copied off the internet where all the comments say that it works. For example
vb.net. This code shows no error, but no message is sent and I've found nothing in the event viewer
Public Shared errorEmailTo As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailTo")
Public Shared errorEmailFrom As String = System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom")
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim email As String = "This is a test email."
show.Text = "To: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailTo") + "<br/>"
show.Text += "From: " + System.Configuration.ConfigurationManager.AppSettings("errorEmailFrom") + "<br/>"
Try
Helper.SendError(email)
show.Text += "No Error"
Catch ex As Exception
show.Text += "Error: " + ex.Message
End Try
End Sub
Public Shared Sub SendError(ByVal strBody As String)
Dim Email As New System.Net.Mail.MailMessage(errorEmailFrom, errorEmailTo)
Email.Subject = "Error Message"
Email.Body = strBody
Dim mailClient As New System.Net.Mail.SmtpClient()
mailClient.UseDefaultCredentials = True
mailClient.EnableSsl = False
Try
mailClient.Send(Email)
Catch ex As Exception
End Try
End Sub
VBS. This code returns the error "The transport failed to connect to the server." For which I've not found anything other than a new nearly identical code block
strSMTPFrom = "donotreply#here.com"
strSMTPTo = "me#here.com"
strSMTPRelay = "localhost"
strTextBody = "Body of your email"
strSubject = "Subject line"
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.TextBody = strTextBody
oMessage.Send
Classic ASP gives the same error message.
<%
Dim sch, cdoConfig, cdoMessage
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "localhost"
.Item(sch & "smtpserverport") = 25
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "donotreply#here.com"
.To = "me#here.com"
.Subject = "Email test"
.TextBody = "This is the test body of the email"
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>
I've found example after example that give these code blocks as working examples, what am I doing wrong?

Brought in a fresh pair of eyes, and we found the answer.
The virtual SMTP server was listening on port 465(SSL), not 25. So with that corrected, classic ASP and VBS worked, but not VB.Net. We created a new Virtual SMTP server, listening on port 587. And as long as VB.Net had SSL disabled it would work. It appears that the new server didn't receive the SSL certificate during migration.

Related

Send automatic email SSL Implicit ASP.NET VB

this code is inside a "for next" loop and sends an email through an implicit SSL server.
Last week I had to change the smtp server and now this new smtp server has a block that does not allow simultaneous connection to more than 5 users.
If the for loop sends more than 5 emails I get the error "Too many simultaneous connections".
I think this occurs because the emails are sent in a NON ASYNCHRONOUS way and consequently the sending of the email takes too long.
I would like to ask if it is possible to use CDO.message ASYNCHRONOUSLY or if you can recommend another code that sends emails synchronously using an implicit SSL server.
Thank you
Dim objEmail = CreateObject("CDO.Message")
Dim objConf = objEmail.Configuration
Dim objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPport
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = cdoTimeout
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasicAuth
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = mailusername
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = mailpassword
.Update()
End With
objEmail.To = email_cli
objEmail.From = ConfigurationManager.AppSettings("p_email")
objEmail.Subject = mailOggetto
objEmail.HTMLBody = testo_email
Try
objEmail.Send()
Catch ex As Exception
FailureText.Text = ex.Message
Exit Sub
Finally
objEmail = Nothing
objConf = Nothing
objFlds = Nothing
End Try

The transport failed to connect to the server in Classic ASP

I want to send a message but I am getting this error. Does anyone have any idea why I am getting this error?
On Error Resume Next
mTo = "*****"
mBody = "<strong>New Signup</strong><br><br> " & _
"Time: " & now() & "<br><br> "
If (mTo <> "") Then
Set objMail = Server.CreateObject("CDO.Message")
With objMail
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' SendUsingPort
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.*****.ca" ' Name or IP of remote SMTP server
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ' Server port
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpConnectionTimeout") = 60
.Configuration.Fields.Update
.From = "Home Style - New Signup <info#******.ca>"
.To = mTo
.Subject = "Home Style - New Signup"
.HTMLBody = mBody
.Send
End with
set objMail = nothing
End If
If Err.Number <> 0 Then
Response.Write (Err.Description)
Response.End
Please let me know where I am missing some code.
looks like you're trying to use authentication, but you're not sending over login details.
see https://stackoverflow.com/a/6500470/5544752 for more info

Sending e-mail using VB on ASP.NET through Gmail

I am trying to send an email from an ASP page using gmail, but when I try to send it, i just get "Error sending mail", with no description other than that.
SMTP is enabled on the gmail box I'm using and also working from mobile devices.
If anyone could give me a hand with this, I'll appreciate it.
Thanks.-
Friend Shared Sub Send_Mail(Destinatario As String)
Dim Message As New MailMessage()
Dim SmtpC = New SmtpClient("smtp.gmail.com")
Message.From = New MailAddress("xxxx#gmail.com")
Message.To.Add(Destinatario)
Message.Subject = "Some Subject"
Message.Body = "Message body"
SmtpC.Port = 465
SmtpC.Credentials = New System.Net.NetworkCredential("xxxx#gmail.com", "somepassword")
SmtpC.EnableSsl = True
Try
SmtpC.Send(Message)
Catch ex As Exception
End Try
End Sub

ASP.net Contact Form Sending an email error

i really need help on one thing. I have a website and in that website i have contact us page in which the users can contact the admin about the page or any other stuff.
The problem is when i try to render the page, it gives me an error saying
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
Source Error:
Line 21: smtp.Credentials = NetworkCred
Line 22: smtp.Port = 587
Line 23: smtp.Send(mm)
Line 24: lblMessage.Text = "Email Sent SucessFully."
Line 25: End Sub
Source File: C:\Users\user\Desktop\ContactUsForm\VB.aspx.vb Line: 23
I really don't know wt to do. My VB behind code is :
Imports System.Net
Imports System.Net.Mail
Partial Class VB
Inherits System.Web.UI.Page
Protected Sub btnSend_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim mm As New MailMessage("sender#gmail.com", "reveiver#gmail.com")
mm.Subject = txtSubject.Text
mm.Body = "Name: " & txtName.Text & "<br /><br />Email: " & txtEmail.Text & "<br />" & txtBody.Text
If FileUpload1.HasFile Then
Dim FileName As String = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName)
mm.Attachments.Add(New Attachment(FileUpload1.PostedFile.InputStream, FileName))
End If
mm.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.EnableSsl = True
Dim NetworkCred As New System.Net.NetworkCredential()
NetworkCred.UserName = "sender#gmail.com"
NetworkCred.Password = "senderpassword"
smtp.UseDefaultCredentials = True
smtp.Credentials = NetworkCred
smtp.Port = 587
smtp.Send(mm)
lblMessage.Text = "Email Sent SucessFully."
End Sub
End Class
The error is at line 23 where it is saying smtp.Send(mm)
I am really in a need. Please can anyone help me.
Change
smtp.UseDefaultCredentials = False
your don't want to use the default credentials, you want to use the credentials you created in your code.
https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.usedefaultcredentials(v=vs.110).aspx

cdonts and relay server?

I use CDONTS when I need to send up send email form on websites. Recently changed my hosting company to godaddy. I realized my send email form gives "permission denied" error. I called GoDaddy support. They told me I should use relay server "relay-hosting.secureserver.net" in my codes. I thought relay server used only with CDO.
How can I include it to my codes?
My codes
Set objEmail = Server.CreateObject("CDONTS.NewMail")
objEmail.To = MailTo
objEmail.Cc = MailCc
objEmail.From = MailFrom
objEmail.Subject = MailSubject
objEmail.Body = MailBody
objEmail.Send
Set objEmail = nothing
A web search for "cdonts relay" yielded this example which relates directly to your issue with GoDaddy.com - Based on everything I've read, this only works with CDO.Message instead of CDONTS.NewMail.
UPDATE: Here's the modified code
Set objMail = Server.CreateObject("CDO.Message")
objMail.From = MailFrom
objMail.To= MailTo
objMail.Subject = MailSubject
objMail.TextBody = MailBody
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"
objMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMail.Configuration.Fields.Update
objMail.Send
set ojbMail = nothing

Resources