|
-
May 31st, 2007, 04:20 PM
#1
Thread Starter
Lively Member
[2005] how to send email notification?
Hi,
I got a question ..
in my application .. I need to send an email notification when user do something
for example, I need to to send an email to user when he insert some data
and the insertion was successful
like here in the forum, we got an email when we first register
how am going to do that?
please help ..
many thanks in advance ..
-
Jun 1st, 2007, 06:32 AM
#2
Re: [2005] how to send email notification?
don't worry about the CreateRequest call or method
vb Code:
Private Sub SendAdminEmail()
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration( _
HttpContext.Current.Request.ApplicationPath)
Dim settings As System.Net.Configuration.MailSettingsSectionGroup = _
CType(config.GetSectionGroup("system.net/mailSettings"), _
MailSettingsSectionGroup)
'Obtain the Network Credentials from the mailSettings section
Dim credential As New NetworkCredential( _
settings.Smtp.Network.UserName, settings.Smtp.Network.Password)
'Create the SMTP Client
Dim client As New SmtpClient()
client.Host = settings.Smtp.Network.Host
client.Credentials = credential
'Build Email Message
Dim email As New MailMessage
email.From = New MailAddress(ConfigurationManager.AppSettings("FakeEmail"))
For Each address As String In ConfigurationManager.AppSettings("SendToAdmin").Split(New Char() {";"}, StringSplitOptions.RemoveEmptyEntries)
email.To.Add(address)
Next
'email.To.Add(ConfigurationManager.AppSettings("SendToAdmin"))
email.Subject = "New WLR User Account Request"
email.IsBodyHtml = True
email.Body = "<strong>A new user has signed up for access to the WLR</strong>"
email.Body += "<br><br><strong>The following information is viewable once you login.</strong><br><br>"
email.Body += "<br><br><strong>Name:</strong> " + Me.lblVerifyName.Text
email.Body += "<br><strong>Address 1:</strong> " + Me.lblVerifyAdd1.Text
email.Body += "<br><strong>Address 2:</strong> " + Me.lblVerifyAdd2.Text
email.Body += "<br><strong>City:</strong> " + Me.lblVerifyCity.Text
email.Body += "<br><strong>State:</strong> " + Me.lblVerifyState.Text
email.Body += "<br><strong>Zipcode:</strong> " + Me.lblVerifyZip.Text
email.Body += "<br><strong>Phone:</strong> " + Me.lblVerifyPhone.Text
email.Body += "<br><strong>Email:</strong> " + Me.lblVerifyEmail.Text
email.Body += "<br><strong>Company:</strong> " + Me.lblVerifyCompany.Text
'Send Email
client.Send(email)
End Sub
Private Sub CreateRequest()
Dim mr As New WlrHelper.MembershipRequest
mr.Name = txtName.Text.Trim
mr.Address1 = txtAdd1.Text.Trim
mr.Address2 = txtAdd2.Text.Trim
mr.City = txtCity.Text.Trim
mr.State = txtState.Text.Trim
mr.Zip = txtZip1.Text.Trim + IIf(Not String.IsNullOrEmpty(txtZip2.Text.Trim), txtZip2.Text.Trim, "")
mr.Phone = txtPhoneAreaCode.Text.Trim + txtPhonePrefix.Text.Trim + txtPhonePostfix.Text.Trim
mr.Email = txtEmail.Text.Trim
mr.Company = txtCompany.Text.Trim
WlrHelper.Logger.AddMembershipRequest(mr)
End Sub
Protected Sub wizRegister_FinishButtonClick(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.WizardNavigationEventArgs) Handles wizRegister.FinishButtonClick
If Me.CaptchaControl1.UserValidated Then
Try
SendAdminEmail()
CreateRequest()
Me.wizRegister.Visible = False
Me.litFinished.Text = "A request has been submitted for the system administrator(s) to review for account activation! A system administrator my contact you by phone or email with you account information. <br /><br />Upon your first sign in you will be required to change your password." '"An email has been sent to the system administrator requesting account activation. The system administrator my contact you by phone or email with you account information. <br /><br />Upon your first sign in you will be required to change your password."
Me.litFinished.Visible = True
Catch ex As Exception
Me.wizRegister.Visible = False
Me.pnlFinished.Font.Size = FontUnit.Point(10)
Me.pnlFinished.ForeColor = Drawing.Color.Red
Me.litFinished.Text = ex.ToString '"An error occured while trying to create a request for the system administrator(s) to review! Please try again." '"An error occured while trying to send information to the accout administrator! Please try again."
Me.litFinished.Visible = True
End Try
End If
End Sub
-
Jun 1st, 2007, 08:29 AM
#3
Re: [2005] how to send email notification?
You really don't need all that code to do it if you are running straight from the server that's sending the email. The Configuration Manager is a great place to store that information, but the reality is, you just need to define the SMTP client, mail.To, mail.From, mail.Subject, and mail.Body, then send it out and clear the object out. I have several scripts running to send out emails based on provided information, and none of them have nearly that much code... except the one that sends two different emails at once...
-
Jun 1st, 2007, 09:55 AM
#4
Addicted Member
Re: [2005] how to send email notification?
-
Jun 1st, 2007, 11:02 AM
#5
Re: [2005] how to send email notification?
 Originally Posted by timeshifter
You really don't need all that code to do it if you are running straight from the server that's sending the email. The Configuration Manager is a great place to store that information, but the reality is, you just need to define the SMTP client, mail.To, mail.From, mail.Subject, and mail.Body, then send it out and clear the object out. I have several scripts running to send out emails based on provided information, and none of them have nearly that much code... except the one that sends two different emails at once...
yea that's very true.... however, i was give him/her an "example"
-
Jun 1st, 2007, 04:34 PM
#6
Thread Starter
Lively Member
Re: [2005] how to send email notification?
thank you vbdotnetboy,
I will try to understand that whole bunch of codes
-
Jun 1st, 2007, 04:39 PM
#7
Thread Starter
Lively Member
Re: [2005] how to send email notification?
timeshifter,
what about posting it here, if u don't mind
-
Jun 3rd, 2007, 10:00 PM
#8
Re: [2005] how to send email notification?
I'll post it tomorrow at work.
-
Jun 4th, 2007, 07:48 AM
#9
Re: [2005] how to send email notification?
As promised. This is a simple script to email to a given parameter and from the AppSettings block of keys.
vb Code:
Public Shared Function EmailPassword(ByVal email As String, ByVal password As String)
Dim msg As New MailMessage
msg.To.Add(New MailAddress(email))
msg.From = New MailAddress(ConfigurationManager.AppSettings("EmailFrom"))
msg.Subject = "Subject"
msg.IsBodyHtml = True
msg.Body = "My message.<br>New line."
Dim smtpClient As New SmtpClient
smtpClient.Host = ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Return True
End Function
-
Jun 4th, 2007, 11:29 AM
#10
Thread Starter
Lively Member
Re: [2005] how to send email notification?
timeshifter, thank you very much
-
Jun 25th, 2007, 01:17 AM
#11
Member
Re: [2005] how to send email notification?
 Originally Posted by timeshifter
As promised. This is a simple script to email to a given parameter and from the AppSettings block of keys.
vb Code:
Public Shared Function EmailPassword(ByVal email As String, ByVal password As String)
Dim msg As New MailMessage
msg.To.Add(New MailAddress(email))
msg.From = New MailAddress(ConfigurationManager.AppSettings("EmailFrom"))
msg.Subject = "Subject"
msg.IsBodyHtml = True
msg.Body = "My message.<br>New line."
Dim smtpClient As New SmtpClient
smtpClient.Host = ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Return True
End Function
sorry for asking a stupid question,
i'm still n00b at ASP.NET n using ASP.NET 1.1
so can u help me on how to send email in ASP.NET 1.1?
Dim Mail As New Mail.MailMessage
Mail.To = txtTo.Text
Mail.From = txtFrom.Text
Mail.Subject = txtSubject.Text
Mail.Body = txtBody.Text
SmtpMail.SmtpServer = "localhost"
SmtpMail.Send(Mail)
that's my code n it doesn't work and the error message is "Can't connect to the server"
as u can see i'm using vb code, so any clue in how to set the smtp server?
Last edited by AeroConfident; Jun 25th, 2007 at 01:33 AM.
-
Jun 25th, 2007, 08:17 AM
#12
Re: [2005] how to send email notification?
I'm afraid I can't help you in 1.1. I keep all important variables defined in the web.config file to ensure consistency. I think the SMTP server for that is defined as the mail server on my internal network... try setting it as 127.0.0.1 and see what it does.
-
Jun 25th, 2007, 09:39 AM
#13
Member
Re: [2005] how to send email notification?
ah.. forget about my previous request.
now i'm changing into ASP.NET 2. and i tried your code.
but it shows errors
msg.From = New MailAddress(ConfigurationManager.AppSettings("localhost"))
it said about the value mustn't null.
n also 1 thing where should i use the parameter "password" in your code?
-
Jun 25th, 2007, 10:14 AM
#14
Re: [2005] how to send email notification?
It's looking for a key in the web.config file called 'localhost'. First, don't use a key called 'localhost', that's just confusing. Timeshifter used EmailFrom. Create a key in your web.config called EmailFrom, and give it a value of your email address.
-
Jun 26th, 2007, 02:17 AM
#15
Member
Re: [2005] how to send email notification?
sorry for asking a n00b Question, but how do i create key in web.config?
<EmailFrom>
localhost
</EmailFrom>
so after set the code i change my code
from
msg.From = New MailAddress(ConfigurationManager.AppSettings("localhost"))
to
msg.From = New MailAddress(ConfigurationManager.AppSettings("EmailFrom"))
-
Jun 26th, 2007, 06:07 AM
#16
Re: [2005] how to send email notification?
This goes under 'configuration'.
-
Jun 26th, 2007, 08:02 AM
#17
Re: [2005] how to send email notification?
To call that later, your VB call will look like:
Code:
Dim emTo As String = ConfigurationManager.AppSettings("EmailFrom")
Oh, and thanks for the personal touch, mendhak.
-
Jun 27th, 2007, 07:03 AM
#18
Member
Re: [2005] how to send email notification?
it works now many thanks to mendhak n timeshifter 
and i wanna to ask another thing, what should i do if u need to authen to the SMTPServer in order to send the email?
-
Jun 27th, 2007, 09:07 AM
#19
Re: [2005] how to send email notification?
Code:
Dim auth As New System.Net.NetworkCredential("userid", "pwd")
smtpClient.Credentials = auth
-
Jul 1st, 2007, 09:28 AM
#20
Member
Re: [2005] how to send email notification?
Thx MendHak
-
Jul 2nd, 2007, 11:39 AM
#21
Re: [2005] how to send email notification?
Add resolved, dude. Big thread, big searches.
-
Jul 3rd, 2007, 01:16 AM
#22
Member
Re: [2005] how to send email notification?
i can't edit the thread, i'm not a topic starter in here. >.<
-
Jul 4th, 2007, 12:07 PM
#23
Re: [2005] how to send email notification?
I should pay more attention. Slap me.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|