Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 20, 2012 10:24 PM by Ahmad Azizov
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 = "email@example.com"
Dim FromAddress As String = "firstname.lastname@example.org"
'(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
'MessageLabel.Text = "An error occurred during the insert operation."
e.KeepInEditMode = True
' MessageLabel.Text = e.Exception.Message
e.ExceptionHandled = True
e.KeepInEditMode = True
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.
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.
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?
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 email@example.com to firstname.lastname@example.org but I can send from email@example.com to firstname.lastname@example.org.
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("email@example.com", "*******");
sc.Credentials = myCreds;
Jun 20, 2012 08:21 PM|LINK
I have that all set up in my web.config file.
<network host="smtp.gmail.com" password="xxx" port="587" userName="firstname.lastname@example.org" />
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 email@example.com, although, it will send to my school email address.
Jun 20, 2012 08:54 PM|LINK
why don't you use debugging to see what happens to that part of your code
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.
Jun 20, 2012 10:24 PM|LINK
It looks very weird. Could you have made a mistake in coding?