>>They are going from "login.aspx" to "contentpage.aspx" and I want
the mail sent when
>>they hit "contentpage.aspx" would that still be a post back? Logging
in automatically
>>sends the client to "contentpage.aspx" and nowhere else.
In this case you are correct, you don't want to do a post back.
>> In English I want to say "Get the userID from the cookie, then
compare it to the dataset
>>and pull "userID" and put it in the subject line, "Email" and put it
in the From line and put
>> a time/date in the message body and send automatically."
Let's step back. You could do this all a lot more simply and
efficiently in your login process. Why wait for the user to hit this
page and have to re-retrieve their information? To perform the login
you need access all this information anyway, why not use it or least
grab it then.
Here's what I'd do...
function Login(username, pwd) as Boolean
Dim Success as Boolean = False
'retrieve user record from the db by username
Dim dr as DataRow = GetUserByName(username)
if not IsNothing(dr) then
'have a user, see if the passwords match
Dim pwdDB as string = dr("Password")
if pwdDB = pwd then
Success = True
'Set Authentication Cookie
FormsAuthentication.SetAuthCookie(username, false)
'Send email
SendMail(dr("UserID"), dr("Email"))
End if
ENd if
Return Success
end function
private function GetUserByName(userName as string) as DataRow
'Create connection
'Fill Datatable with DataAdapter
'return row if one is found
End function
private const SEND_TO_ADDRESS = "[EMAIL PROTECTED]"
private sub SendMail(userID as string, From as string)
Dim objMsg As New System.Web.Mail.MailMessage()
With objMsg
.To = SEND_TO_ADDRESS
.From = From
.Subject = userID
.Body = "Logged in: " & DateTime.Now().ToString()
End With
System.Web.Mail.SmtpMail.Send(objMsg)
end sub
If you need help on the database stuff, let me know.
Also, unless you have opened up your email server, you might not be
able to use the user's email address as the FROM setting. You might
just want to include their email address in the body and use a set
FROM address.
Another note, I've used a constant hre, but I'd usually set the TO
address in the web.config file and retrieve it from there, so it could
be changed without having to recompile the code. I'd do the same for
the FROM address as well.
ToAddress = ConfigurationSettings.AppSettings("ToAddress")
On 11/7/05, Jeff Gramins <[EMAIL PROTECTED]> wrote:
> They are going from "login.aspx" to "contentpage.aspx" and I want the mail
> sent when they hit "contentpage.aspx" would that still be a post back?
> Logging in automatically sends the client to "contentpage.aspx" and nowhere
> else.
>
> Also, how do I populate the "From", "Subject" and "Body" (Page viewed at
> DateTime) dynamically? I understand that it has to be pulled from the
> authentication cookie placed by the login.aspx page and matched to a dataset
> and I need to create a dataset for the "contentpage.aspx" but I'm not quite
> sure about the syntax of how to do it.
>
> In English I want to say "Get the userID from the cookie, then compare it to
> the dataset and pull "userID" and put it in the subject line, "Email" and put
> it in the From line and put a time/date in the message body and send
> automatically."
>
> Thank you for the help.
>
> Jeff
> ----- Original Message -----
> From: Dean Fiala
> To: [email protected]
> Sent: Monday, November 07, 2005 8:04 PM
> Subject: Re: [AspNetAnyQuestionIsOk] Re: Send Mail on Page Load
>
>
> Your basic idea is right, though your syntax is off. You've embedded
> a function declaration in If..then block. Also Yuo probably want to
> send you mail when the user posts back to the form, not when they view
> the page (you won't know who they are).
>
> I'd so something like this...
> Sub Page_Load()
>
> If Page.IsPostBack then
> If Login(username, pwd) = true then
> SendMail(your parms here )
> End if
> End if
> End Sub
>
> Public Function SendMail (By Val [To] As String
> ByVal Body As String, ByVal IsHTML As Boolean, _
> Optional ByVal SmtpServer As String = "domain.com") As
> Boolean
>
> Dim objMsg As New System.Web.Mail.MailMessage()
> SendMail = True
> With objMsg
> .To = [To]
> .From = From
> .Subject = Subject
> .Body = Body
> End With
> System.Web.Mail.SmtpMail.SmtpServer = SmtpServer
> System.Web.Mail.SmtpMail.Send(objMsg)
> Catch
> SendMail = False
> End Try
> End Function
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/