Send emails to selected users based on Form input

Send emails to selected users based on Form input
0

#1

I am using ASPRunner.NET Version 9.8. I am trying to setup both my Add and Edit page to send emails to users that are selected to receive additions and updates. For example, we have a ticketing system that users add tickets to and on the Add page, they can select who needs to know about this ticket. The field lists the persons name, but when the record is added it actually saves the user’s email address. I would like the user to get an email with the ticket info after the record is saved. How would I do this in ASPRunner.NET? I am guessing it would either be JavaScript or C# code. I would prefer to use code rather than a button since the user will already have to hit one button to save. Thanks!


#2

You would use C# code, because sending the email is a back-end process.


#3

Thanks for responding! Would you happen to have any sample code that you could share with me? I have this code that was built-in by the tool, but is different than what I want to use. Is there anyway it can be changed slightly?

var rs = GlobalVars.dal.Table(“UsersTableName”).QueryAll();

XVar data;

var rmail = XVar.Array();

while (data = CommonFunctions.db_fetch_array(rs))

{

rmail[“to”] = data[“EmailAddress”];

rmail[“body”] = “Check what’s hot this season”;

rmail[“subject”] = “Monthly newsletter”;

var ret = MVCFunctions.runner_mail(rmail);

if(!ret[“mailed”])

MVCFunctions.Echo(ret[“message”]);

}


#4

What do you want to do differently?


#5

I am using a field on the Form to store the email addresses not a table. I was hoping that the field that I am using would be referenced rather than a table. It would be stored on the page during the save process when the record is added to the database. Does that make sense?


#6

I assume you are submitting a form when the save button is clicked? If so, just reference that form field which is passed via POST method. If the name attribute of the field containing the email address was “emailaddress”, then you would access that field’s value like:

Request.Form("emailaddress") 

#7

Would I replace the “to” line in the code above with what you wrote? Or would I replace the first line or code with what you wrote? By the way, thanks for the quick responses!


#8

What do you think you should do, since Request.Form(“emailaddress”) should contain the email address? Also, be sure to perform some kind of validation on the front-end and on the server side to make sure it is a valid email syntax, plus you should write code to handle any errors which could arise in the sending process. See this page for examples.


#9

First off, thanks again for the information! I just tried to build the code after adding it and the build did not succeed and I got an error message which I have added below. Apparently, the rapid application development tool that I am using doesn’t like Request. I am going to see what built in code would work better for my project.

include\caldaily_TableEvents.cs(453,16): error CS0103: The name ‘Request’ does not exist in the current context [U:\ASPRunnerNETProjects\Version 9.8 projects\ChangeControlCalendarNEW\output\ChangeControlCalendarNEWEventsCS.csproj]


#10

I think I might have figured it out, but need my Network team to lighten our security settings a little. I used values[EmailAddress].ToString() and it compiled. I am just getting a transmit error which is not related to ASP. Thanks again!