So I have an asp.net server running on discountasp.net and for whatever reason when I just published the new version of the website it stopped sending emails. I tried changing the code back to exactly how it was done in the old website and it didn't work. I've tried many other solutions to no avail. Here's the old code:
Dim message As New MailMessage
message.IsBodyHtml = True
message.From = New MailAddress("example#mydomain.com", "inquiry#mydomain.com")
If Me.ddlSendTo.SelectedValue = 1 Then
message.To.Add(New MailAddress("sales#mydomain.com"))
message.Subject = "Sales Inquiry From mydomain.com"
ElseIf Me.ddlSendTo.SelectedValue = 2 Then
message.To.Add(New MailAddress("support#mydomain.com"))
message.Subject = "Support Question From mydomain.com"
End If
Dim sb As New StringBuilder()
sb.Append("The following message was sent from a user of our website as a request for more information.<br/><br/>")
sb.Append("Here is the message they sent:<br/><br/>")
sb.Append("Sender's Name: " & Me.txtSenderName.Text & "<br/>")
sb.Append("Senders Email: <a href='mailto:" & Me.txtSenderEmail.Text & "'>" & Me.txtSenderEmail.Text & "</a><br/>")
sb.Append("Company Name: " & Me.txtCompany.Text & "<br/>")
sb.Append("Phone Number: " & Me.txtPhone.Text & "<br/><br/>")
sb.Append("Subject: " & Me.txtSubject.Text & "<br/>")
sb.Append("Message: " & Me.txtEmailMsg.Text)
message.Body = sb.ToString()
Try
Dim client As New SmtpClient()
client.Host = "localhost"
client.Send(message)
Catch ex As SmtpException
Me.errors.InnerHtml = ex.Message & " local host message"
Return
End Try
Here's my current iteration that is still not working:
Dim toEmail As String
Dim subject As String
If Me.ddlSendTo.SelectedValue = 1 Then
If isTesting() Then
toEmail = GetTesterEmail()
Else
toEmail = "sales#mydomain.com"
End If
subject = "Sales Inquiry From MyDomain.com"
ElseIf Me.ddlSendTo.SelectedValue = 2 Then
If isTesting() Then
toEmail = GetTesterEmail()
Else
toEmail = "support#mydomain.com"
End If
subject = "Support Question From MyDomain.com"
End If
Dim sb As New StringBuilder()
sb.Append("The following message was sent from a user of our website as a request for more information.<br/><br/>")
sb.Append("Here Is the message they sent:<br/><br/>")
sb.Append("Sender's Name: " & Me.txtName.Value & "<br/>")
sb.Append("Senders Email: <a href='mailto:" & Me.txtEmail.Value & "'>" & Me.txtEmail.Value & "</a><br/>")
sb.Append("Company Name: " & Me.txtCompany.Value & "<br/>")
sb.Append("Phone Number: " & Me.txtPhone.Value & "<br/><br/>")
sb.Append("Subject: " & Me.txtSubject.Value & "<br/>")
sb.Append("Message: " & Me.txtMessage.Value)
'message.Body = sb.ToString()
Dim message As New MailMessage("postmaster#mydomain.com", toEmail, subject, sb.ToString())
message.IsBodyHtml = True
Try
Dim client As New SmtpClient()
client.Host = "smtp.mydomain.com"
client.Port = 25
client.Credentials = New System.Net.NetworkCredential("postmaster#mydomain.com", "password")
client.Send(message)
Catch ex As SmtpException
Me.errors.Text = ex.Message & " local host message"
Return
End Try
I tried leaving off network credentials, leaving off port, leaving off the #mydomain.com on the network credentials. Nothing works
Related
I want to send image also with mail but not attachment I want to send like an invitation or request with company logo like a card
following is my code
Sub SenMail()
Dim mail2 As MailMessage = New MailMessage()
mail2.From = New MailAddress("erpnoreplyy#gmail.com")
mail2.To.Add("shahbaz1604a#aptechgdn.net")
mail2.Subject = "test email"
'text/html
'Dim plainview As AlternateView = AlternateView.CreateAlternateViewFromString("this is my text", Nothing, "plain/html")
'Dim htmlview As AlternateView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.<img src=cid:companylogo>", Nothing, "text/html")
Dim logo As LinkedResource = New LinkedResource("f:\\logindreuss.gif", MediaTypeNames.Image.Gif)
logo.ContentId = "MyImage"
'logo.ContentId = "logo"
Dim body As String = "" &
"<img src=cid:MyImage width='100px' height='100px' alt='logostring'>"
'"<img src='" & htmlview.ToString() & "' alt='htmlstring'>" &
'"<img src='" & plainview.ToString() & "' alt='plainstring'>"
mail2.IsBodyHtml = True
mail2.Body = body
'htmlview.LinkedResources.Add(logo)
'mail2.AlternateViews.Add(plainview)
'mail2.AlternateViews.Add(htmlview)
'Dim smtp As SmtpClient = New SmtpClient("465.0.0")
Dim av As AlternateView = AlternateView.CreateAlternateViewFromString(body, Nothing, MediaTypeNames.Text.Html)
av.LinkedResources.Add(logo)
Dim smtp As SmtpClient = New SmtpClient()
smtp.Port = 587
smtp.Host = "smtp.gmail.com"
smtp.Credentials = New System.Net.NetworkCredential("erpnoreplyy#gmail.com", "naeem1234")
smtp.EnableSsl = True
smtp.Send(mail2)
End Sub
Here you can convert your image to byte and pass it to mail body as html, If Image is still not showing then you have to decode that Base64String online and you get simple URI and put in your img tag of body
Dim b_logo = File.ReadAllBytes("C:\Users\yogesh\Pictures\sclhneider.png")
Dim body As String = "<img src='data:image/png;base64," & Convert.ToBase64String(b_logo) & "' />"
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
Hi im doing a ASP contact form and for some reason i keep getting this.
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
/confirmation.asp, line 10
800401f3
I think that theres something wrong with my SMTP, please any help would be grateful.
<%
DIM strEmail, strFirstName, strLastName, strSubject, strComments
strEmail = request.form("Email")
strFirstName = request.form("FirstName")
strLastName = request.form("LastName")
strSubject = request.form("Subject")
strComments = request.form("Comments")
DIM Mailer,strMsgHeader, qryItem, strMsgInfo
Set Mailer = Server.CreateObject("smtpout.secureserver.net")//this line might be wrong.
Mailer.FromName = "Web Designs"
Mailer.FromAddress= "carlos#example.net"
Mailer.ReplyTo = strEmail
Mailer.RemoteHost = "mail.example.net"
Mailer.AddRecipient "", ""
Mailer.Subject = "Online Inquiry"
strMsgHeader = "This mail message was sent from the Online Form" & vbCrLf & vbCrLf
Mailer.BodyText = strMsgHeader & vbCrLf & "Email: " & Request.Form("Email") & _
vbCrLf & "First Name: " & Request.Form("FirstName") & _
vbCrLf & "Last Name: " & Request.Form("LastName") & _
vbCrLf & "Subject: " & Request.Form("Subject") & _
vbCrLf & "Comments: " & Request.Form("Comments")
IF Mailer.SendMail THEN
Response.Write strFirstName & ",<br>"
Response.Write "Your message has been successfully sent."
ELSE
Response.Write "The following error occurred while sending your message: " & Mailer.Response
END IF
%>
It seems you mix up the 'send email library' and your SMTP configuration.
the Mailer should look like
Set Mailer = Server.CreateObject("CDO.Message")
(although this could depend on your IIS version)
To configure your SMTP you should use this object:
Set cdoConfig = CreateObject("CDO.Configuration")
cdoConfig.Fields.Item(cdoSMTPServer) = "smtpout.secureserver.net"
Edit: example code: CDO Classic ASP form not working
I am trying to debug this issue when sending this information from a form, but I keep getting this error.
error '8004020e'
/contacthandler.asp, line 45
I have not done much work in asp, but I've managed to clean this file up a little bit from the previous developer (still had the error). The error happens at the .Send..forgot to clarify that.
Here is the code. Any help is appreciated.
'declare variables
dim name, phone, email, comment, service, returnPage
'set variables to the corresponding fields from contact form
name = request.form("custName")
phone = request.form("custPhone")
email = request.form("custEmail")
comment = request.form("custNotes")
service = request.form("service")
returnPage = request.form("page")
dim theEmail
' set the email content data
theEmail = "<h3>Contact from website, information below.</h3><table border='0'><tr><th>Customer Name:<td>"&name
theEmail = theEmail&"<tr><th>Phone Number:<td>"&phone&"<tr><th>Email Address:<td>"&email&"<tr><th>Service Category:<td>"&service
theEmail = theEmail&"<tr><th valign='top'>Comments/Notes:<td>"&comment&"</table>"
' send the email
dim sch
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserverport") = 587
.Item(sch & "smtpserver") = "smtp.office365.com"
.Item(sch & "smtpauthenticate") = 1
.Item(sch & "sendusername") = "########"
.Item(sch & "sendpassword") = "########"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = name & "<" & email & ">"
.To = "info#mywebsite.com"
.Subject = "Website - "&service&" Request"
.HTMLBody = theEmail
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
'response.write "sent, check the mail"
response.redirect "thankyou.asp"
'returnPage&".asp"
MSDN (http://msdn.microsoft.com/en-us/library/ms527318%28v=exchg.10%29.aspx) suggests you need to format your .From field as follows:
.From """" & name & """ <" & email & ">"
I used Google to look up the error code and I found lots of sites they meant there is an issue with sending the data. That can be another source of trouble.
What will happen if you replace
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
by
.Item(cdoSendUsingMethod) = 1 'cdoSendUsingPickup
Additional try it without any comments.
Here is the codes:
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Dim attachment As System.Net.Mail.Attachment
SmtpServer.Credentials = New _
Net.NetworkCredential("administrator#company.com", "1234")
SmtpServer.Port = 25
SmtpServer.Host = "SmtpServer"
mail = New MailMessage()
mail.From = New MailAddress("user#company.com.my")
mail.To.Add("recipient#external.com")
mail.CC.Add("user1#company.com")
mail.CC.Add("user2#company.com")
mail.Headers.Add("Disposition-Notification-To", "user1#company.com") 'Read receipt
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure 'Fail delivery notification
mail.Subject = "Sending Documents"
mail.Body = "To Whom May Concern," & vbCrLf _
& vbCrLf & "Please refer to the attachment for the documents." & vbCrLf & _
"NOTE : This is an automatically generated email and will be sent daily."
For Each path As String In attch
attachment = New System.Net.Mail.Attachment(path)
mail.Attachments.Add(attachment)
Next
Try
SmtpServer.Send(mail)
SmtpServer = Nothing
Catch ex As Exception
Response.Write(ex.ToString)
Exit Sub
End Try
Problem is only internal email receiving, not external email.
No errors shown during the code execution.
Any idea on how to solve this?
Or do I need to configure something at the Microsoft Exchange Server?
Also the server using the MailMarshal to do the filtering.
An advanced thanks for the contributing feedback.
Make sure that "mail.From" value is in the list allowed by SMTP server. It could be that relaying is not allowed.