Victor Charles
asked on
Help with sending email to admistrator when user registers in Login Page
Hello,
How do I setup my login page to send an email when users register to access my ASP.NET site?
How do I setup my login page to send an email when users register to access my ASP.NET site?
Ooops, just noticed a copy/paste flub-up.
This: MailMessage mailmessage = mailmessage = new MailMessage();
Should be this: MailMessage mailmessage = new MailMessage();
This: MailMessage mailmessage = mailmessage = new MailMessage();
Should be this: MailMessage mailmessage = new MailMessage();
ASKER
Thanks for the code, but my project is in VB.NET, do you have VB.NET version. I don't understand why I need to enter the IP address and port information. I will deploy this product to a web server, do you mean I need the server's IP address and port information in order to use this feature?
Ok, so you need to know the IP address and port number that your mail server is using. Most hosting companies, such as GoDaddy, have several servers separated from their web servers, that do nothing but relay email. The hosting company will tell you the IP and Port needed to connect to these mail servers. At GoDaddy they are something like this:
IP: yourdomain.secureserver.ne t
Port: 25
Also, almost all hosting companies have their mail servers setup to require a username and password when sending mail. The username is typically the email address, and the password is whatever password you used when setting up the email address. These are used to authenticate to the mail server so that only known email accounts can send email.
Even if you are setting up your own web server in your house, the .Net Framework's email sending functionality requires the IP address and Port number, as they are needed for the system to know how to send the message over the network.
Below is the above C# code converted to VB:
And to use it would be like this:
IP: yourdomain.secureserver.ne
Port: 25
Also, almost all hosting companies have their mail servers setup to require a username and password when sending mail. The username is typically the email address, and the password is whatever password you used when setting up the email address. These are used to authenticate to the mail server so that only known email accounts can send email.
Even if you are setting up your own web server in your house, the .Net Framework's email sending functionality requires the IP address and Port number, as they are needed for the system to know how to send the message over the network.
Below is the above C# code converted to VB:
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Net
Imports System.Net.Mail
Imports System.Web
Public Class Email
Public From As String = "noreply@your-domain.com"
Public _To As String = String.Empty
Public Subject As String = String.Empty
Public Message As String = String.Empty
Public Sub Email()
End Sub
Public Sub Email(ByVal _to As String, ByVal subject As String, ByVal message As String)
Me._To = _to
Me.Subject = subject
Me.Message = message
End Sub
Public Sub Email(ByVal from As String, ByVal _to As String, ByVal subject As String, ByVal message As String)
Me.From = from
Me._To = _to
Me.Subject = subject
Me.Message = message
End Sub
Public Function Send() As Boolean
Dim smtp As New SmtpClient("")
smtp.Port = 26
smtp.EnableSsl = False
smtp.Credentials = New NetworkCredential("username", "password")
Dim html As AlternateView = AlternateView.CreateAlternateViewFromString(Me.Message, Nothing, "text/html")
Dim mailmessage As New MailMessage()
mailmessage.From = New MailAddress(Me.From, "Email Display Name")
mailmessage.To.Add(Me._To)
mailmessage.Subject = Me.Subject
mailmessage.AlternateViews.Add(html)
Try
smtp.Send(mailmessage)
Return True
Catch ex As Exception
Dim err As String = ex.ToString()
Return False
End Try
End Function
End Class
And to use it would be like this:
Dim email As String = "user@email.com"
Dim message As New StringBuilder()
message.Append("Some message text to send.")
message.Append("Some more stuff.")
message.Append("<p>Some embeded html in the email</p>")
Dim mail As Email = New Email(email, "Thanks for Registering", message.ToString())
mail.Send()
ASKER
Hi,
Where in the form do I include the second part of your code?
Thanks,
Victor
Where in the form do I include the second part of your code?
Thanks,
Victor
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank You!
Here is a email class that I wrote:
Open in new window
Then to use it you would do something like shown below. Also, don't get too hung up on the activation key thing, I was just adding that in as a rough example of what I do when a users registers at one of my websites.
Open in new window