Vindhya Yadaav

Vindhya Yadaav

  • NA
  • 36
  • 11k

For Sending Mail SMTP HOST???

Aug 10 2016 1:51 AM

// Initialize WebMail helper

WebMail.SmtpServer = "your-SMTP-host";????

WebMail.SmtpPort = 25;????

WebMail.UserName = "your-user-name-here";????

WebMail.Password = "your-account-password";???

WebMail.From = "your-email-address-here";????

Give with an full example....
 
 
 
full coding.??
 

? Add a new page named ProcessRequest.cshtml to the website and add the following code and markup:

@{

var customerName = Request["customerName"];

var customerEmail = Request["customerEmail"];

var customerRequest = Request["customerRequest"];

var errorMessage = "";

var debuggingFlag = false;

try {

// Initialize WebMail helper

WebMail.SmtpServer = "your-SMTP-host";

WebMail.SmtpPort = 25;

WebMail.UserName = "your-user-name-here";

WebMail.Password = "your-account-password";

WebMail.From = "your-email-address-here";

// Send email

WebMail.Send(to: customerEmail,

subject: "Help request from - " + customerName,

body: customerRequest

);

}

catch (Exception ex ) {

errorMessage = ex.Message;

}

}

<!DOCTYPE html>

<html>

<head>

<title>Request for Assistance</title>

</head>

<body>

<p>Sorry to hear that you are having trouble, <b>@customerName</b>.</p>

@if(errorMessage == ""){

<p>An email message has been sent to our customer service

department regarding the following problem:</p>

<p><b>@customerRequest</b></p>

}

else{

<p><b>The email was <em>not</em> sent.</b></p>

<p>Please check that the code in the ProcessRequest page has

correct settings for the SMTP server name, a user name,

a password, and a "from" address.

</p>

if(debuggingFlag){

<p>The following error was reported:</p>

<p><em>@errorMessage</em></p>

}

}

</body>

</html>

 

Answers (7)