asp.net - How could I recreate a PHP mail script in ASP? -


i'm trying create simple, stand-alone asp script reads variables posted jquery ajax call , sends email based on of values. however, new asp , having trouble converting it.

from research, appears asp equivalent of $_get['var_name'] request.querystring['var_name']. however, sending email, have stumbled across dozens , dozens of examples using aspemail, cdosys, ipworksmail, jmail, , on. have tried few , tend no positive results.

here i'm trying accomplish in asp, written in php:

<?php   if($_get['val1'] != "") {     // add section 1 email.   }    if($_get['val2'] != "") {     // add section 2 email   }    $email_company = mail($_get['company_email'], $subject, $message, $headers);   $email_client = mail($_get['client_email'], $subject, $message, $headers);    if($email_company && $email_client) {     echo 'success';   }   else {     echo 'error';   }  ?> 

so, should looking use emails? can made page standalone, can sit , receive ajax calls? thank time.

edit:

i have been trying stuff , without fail 500 server error. cannot view error messages 500 page, don't know problem.

<%=   ' create mail message dim mail new mailmessage  ' set address information mail.from = new mailaddress("from@website.com")  mail.to.add("to@website.com")  ' set content of email mail.subject = "testing email" mail.body = "hello, test email!"  ' send message dim smtp new smtpclient("mail server") smtp.enablessl = false smtp.credentials = new system.net.networkcredential("username", "passsword") smtp.port = 25  smtp.send(mail)    %> 

here's example using standalone page , webmethod. if you're still having problems, issue web server configuration. if you're using iis, make sure you've set page in either virtual directory or application inside of website proper bindings. try making simple html page @ location make sure page reachable (and "where" think is).

cheers.

 <%@ page language="c#" %>   <script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <script>      $(function () {          var params = {};         params['from'] = 'fake@test.com'         params['to'] = 'fakeone@test.com;faketwo@test.com';         params['body'] = 'hello world';                 $.ajax({             type: 'post',             url: 'default.aspx/sendmail',             data: json.stringify(params),             contenttype: 'application/json; charset=utf-8',             datatype: "json"         });     }); </script>  <script runat="server">       [system.web.services.webmethod]     public static void sendmail(string to, string from, string body)      {          var mail = new system.net.mail.mailmessage();         mail.body = body;         mail.from = new system.net.mail.mailaddress(from);         foreach (var r in to.split(';'))             mail.to.add(r);          var smtp = new system.net.mail.smtpclient("mail.yourdomain.com");          smtp.send(mail);      }  </script> 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -