This is a migrated thread and some comments may be shown as answers.

Problem sending emails using Rad Editor in Grid

2 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ILJIMAE
Top achievements
Rank 1
ILJIMAE asked on 27 Aug 2014, 07:57 AM
Hello,

I have created a webform (ASP.NET C#) named "SendEmails.aspx".

This webform has RadGrid named 'RadGrid1' and a button inside the Record Edit-Template area of RadGrid1 which, when clicked, sends out an email message to the email address typed in to the text box named 'txtEmail' which is also inside the template area of RadGrid1.

The email message's body text comes from the message typed in to the Telerik RAD editor named 'RadEditor1' placed inside the Edit-Template area of RadGrid1.

The email message's subject comes from the text typed into the text box named 'txtEmailSubject' which is also placed on the Edit-Template area of RadGrid1.

The code I'm using to send out the email when the button is clicked is shown below.

protected void Send_Confirmation_Email(object sender, EventArgs e)
        {
            MailMessage myMessage = new MailMessage();
 
 
            //The 4 lines of code shown below is for receiving the content stored in the RADEditor control 'RadEditor1'.
            //and stores in the string variable named 'content'.
            Button GetContent = (Button)sender;
            GridEditFormItem item = (GridEditFormItem)GetContent.NamingContainer;
            RadEditor radEditor = ((RadEditor)item.FindControl("RadEditor1"));
            string content = radEditor.Content;
 
 
            TextBox txtEmail = item.FindControl("txtEmail") as TextBox;
            TextBox txtFirstname = item.FindControl("txtFirstname") as TextBox;
            TextBox txtSurname = item.FindControl("txtSurname") as TextBox;
            TextBox txtEmailSubject = item.FindControl("txtEmailSubject") as TextBox;
 
            string EmailAddress = txtEmail.Text;
            string ToName = txtFirstname.Text + " " + txtSurname.Text;
            string EmailSubject = txtEmailSubject.Text;
 
            myMessage.Body = content;
            myMessage.From = new MailAddress("admin@mydomainname.com", "Support");
            myMessage.To.Add(new MailAddress(EmailAddress, ToName));
            myMessage.Subject = EmailSubject;
            //myMessage.Subject = "New email message subject";
            SmtpClient mySmtpClient = new SmtpClient();
            myMessage.IsBodyHtml = true;
            mySmtpClient.UseDefaultCredentials = true;
            mySmtpClient.Send(myMessage);
 
 
        }

When the button is clicked, the email message is sent out OK.

But, the strange thing is, the email message's subject line always shows the subject text that I have been using 3 days ago ("Confirmation Letter") and it doesn't show/use the text typed in to the 'txtEmailSubject' by the user where this email message should get it's subject line from. No matter whatever text I typed into the 'txtEmailSubject' text box, the email message always uses the text "Confirmation letter" as the subject of the email message. Even if I hard type the subject as "New email message subject" into the code shown above, the change isn't reflected.

Moreover, again, strangely, the email message's SENDER isn't admin@mydomainname.com that I have typed in to the code shown above, but the email message shows the sender is info@mydomainname.com that I have been using 3 days ago.How can this happen?Is this caused by ASP.NET or IIS caching? I have tried changing the SMTP server, deleting all caches for IE, Firefox, Chrome but didn't solve the problem at all.

But. the email message's body text shows the correct message typed into the Telerik Rad editor.

Please explain how to solve this problem.

Thank you.



2 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 28 Aug 2014, 08:22 AM
Hello,

It seems that the information you enter in the UI controls (textboxes, RadEditor, etc) is coming correctly in the code behind. You can debug the Send_Confirmation_Email method to make sure, but if the problem persists even when you hardcode the subject or sender of the message then it seems more of an issue related to the settings and configuration of the e-mail server rather than the code-behind or the UI controls. 
You can double check the configuration of the SMTP server and restart both the SMTP and the IIS to make sure it has not cached any settings. Additionally you can check the server settings and configuration to see if it has anywhere hardcoded the old subject and sender of the e-mail, which can override the settings coming from the code.

Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
ILJIMAE
Top achievements
Rank 1
answered on 28 Aug 2014, 10:36 AM
Marin, Thank you very much for your help,
I will check MailEnable SMTP server settings on my web server and restart it and see if it fixes the problem.
Tags
Grid
Asked by
ILJIMAE
Top achievements
Rank 1
Answers by
Marin
Telerik team
ILJIMAE
Top achievements
Rank 1
Share this question
or