I am trying to set up this grid view so that when I go into edit mode and change the status column to "approved," "denied," or "pending" and update it, then GridView will send out an email to that user. As of now it just seems to be taking awhile to load
after I click the save button on update, but no email is being sent. I have even hardcoded in all of the email addresses and text (so none of the variables are actually called) and still no luck.
Protected Sub TimeOffRequestReport_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) Handles TimeOffRequestReport.RowUpdated
If e.Exception Is Nothing Then
If e.AffectedRows = 1 Then
Dim from_date_requested As Label = CType(TimeOffRequestReport.FindControl("InsertFromDate"), Label)
Dim to_date_requested As Label = CType(TimeOffRequestReport.FindControl("InsertToDate"), Label)
Dim comment As Label = CType(TimeOffRequestReport.FindControl("comment"), Label)
Dim employee As Label = CType(TimeOffRequestReport.FindControl("employee"), Label)
Dim manager As String = lblmanager.Text
Dim email As String = "@reliaquest.com"
Dim approve_deny As Label = CType(TimeOffRequestReport.FindControl("lblApproveDeny"), Label)
Dim ToAddress As String = "test@security.com"
Dim FromAddress As String = "test@security.com"
'(1) Create the MailMessage instance
Dim mm As New MailMessage(FromAddress, ToAddress)
'(2) Assign the MailMessage's properties
mm.Subject = "Timeoff Request"
mm.Body = "text"
mm.IsBodyHtml = True
'(3) Create the SmtpClient object
Dim smtp As New SmtpClient
'(4) Send the MailMessage (will use the Web.config settings)
smtp.EnableSsl = True
smtp.Send(mm)
Response.Redirect("comm_timeoff_request.aspx")
Else
'MessageLabel.Text = "An error occurred during the insert operation."
e.KeepInEditMode = True
End If
Else
' MessageLabel.Text = e.Exception.Message
e.ExceptionHandled = True
e.KeepInEditMode = True
End If
End Sub
The web config file is set up correctly as well, because an email is sent when an item is added to the table on another form.
Ok, so I found half of my problem -- the Handle was actuallying causing it to fire twice, giving the wrong to and from address. So I have fixed that and check all of the other variables, but still no email is being sent when the row is updated and the event
runs all the way through.
It's being sent through the gmail server. I just retested it with another email that is not on my server and it worked, so for some reason I can't send from me@mywebsite.com to me@mywebsite.com but I can send from me@mywebsite.com to me@anotherwebsite.com.
It sends and recieves emails on my other page where I call it on ItemInsert on FormView. But this page for some reason wont send the email to me@xxx.com, although, it will send to my school email address.
I have. It looks like the email is being sent, but nothing is ever recieved by my email address on my work server, only ever recieved on my school server.
ReliaDev
Member
31 Points
74 Posts
Send an Email on GridView Update
Jun 20, 2012 01:18 PM|LINK
I am trying to set up this grid view so that when I go into edit mode and change the status column to "approved," "denied," or "pending" and update it, then GridView will send out an email to that user. As of now it just seems to be taking awhile to load after I click the save button on update, but no email is being sent. I have even hardcoded in all of the email addresses and text (so none of the variables are actually called) and still no luck.
Protected Sub TimeOffRequestReport_RowUpdated(ByVal sender As Object, ByVal e As GridViewUpdatedEventArgs) Handles TimeOffRequestReport.RowUpdated If e.Exception Is Nothing Then If e.AffectedRows = 1 Then Dim from_date_requested As Label = CType(TimeOffRequestReport.FindControl("InsertFromDate"), Label) Dim to_date_requested As Label = CType(TimeOffRequestReport.FindControl("InsertToDate"), Label) Dim comment As Label = CType(TimeOffRequestReport.FindControl("comment"), Label) Dim employee As Label = CType(TimeOffRequestReport.FindControl("employee"), Label) Dim manager As String = lblmanager.Text Dim email As String = "@reliaquest.com" Dim approve_deny As Label = CType(TimeOffRequestReport.FindControl("lblApproveDeny"), Label) Dim ToAddress As String = "test@security.com" Dim FromAddress As String = "test@security.com" '(1) Create the MailMessage instance Dim mm As New MailMessage(FromAddress, ToAddress) '(2) Assign the MailMessage's properties mm.Subject = "Timeoff Request" mm.Body = "text" mm.IsBodyHtml = True '(3) Create the SmtpClient object Dim smtp As New SmtpClient '(4) Send the MailMessage (will use the Web.config settings) smtp.EnableSsl = True smtp.Send(mm) Response.Redirect("comm_timeoff_request.aspx") Else 'MessageLabel.Text = "An error occurred during the insert operation." e.KeepInEditMode = True End If Else ' MessageLabel.Text = e.Exception.Message e.ExceptionHandled = True e.KeepInEditMode = True End If End SubThe web config file is set up correctly as well, because an email is sent when an item is added to the table on another form.
ReliaDev
Member
31 Points
74 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 07:20 PM|LINK
Ok, so I found half of my problem -- the Handle was actuallying causing it to fire twice, giving the wrong to and from address. So I have fixed that and check all of the other variables, but still no email is being sent when the row is updated and the event runs all the way through.
Ahmad Azizov
Member
117 Points
98 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 07:50 PM|LINK
Do you want to send the email from your website or from others such as gmail, yahoo,etc?
ReliaDev
Member
31 Points
74 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 07:57 PM|LINK
It's being sent through the gmail server. I just retested it with another email that is not on my server and it worked, so for some reason I can't send from me@mywebsite.com to me@mywebsite.com but I can send from me@mywebsite.com to me@anotherwebsite.com.
Ahmad Azizov
Member
117 Points
98 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 08:08 PM|LINK
i just tested mine and it sends email from gmail to gmail
in your codes i think u should use the following codes(C#) :(using system.net)
SmtpClient sc = new SmtpClient("smtp.gmail.com", 587);
NetworkCredential myCreds = new NetworkCredential("myemail@gmail.com", "*******");
sc.Credentials = myCreds;
ReliaDev
Member
31 Points
74 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 08:21 PM|LINK
I have that all set up in my web.config file.
It sends and recieves emails on my other page where I call it on ItemInsert on FormView. But this page for some reason wont send the email to me@xxx.com, although, it will send to my school email address.
Ahmad Azizov
Member
117 Points
98 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 08:54 PM|LINK
why don't you use debugging to see what happens to that part of your code
ReliaDev
Member
31 Points
74 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 08:58 PM|LINK
I have. It looks like the email is being sent, but nothing is ever recieved by my email address on my work server, only ever recieved on my school server.
Ahmad Azizov
Member
117 Points
98 Posts
Re: Send an Email on GridView Update
Jun 20, 2012 10:24 PM|LINK
It looks very weird. Could you have made a mistake in coding?