Question

How can I simply set up a SMTP in my personal html code? Example code would...

How can I simply set up a SMTP in my personal html code? Example code would be helpful with GET and POST methods.

0 0
Add a comment Improve this question Transcribed image text
Answer #1




Hi here i am providing you the HTML code along with System.Net.Mail;
HTML Form to send an Email using SMTP Server.

POST Method in HTML Form:-
=========================

<form method="post" name="mail" action="mailpage.jsp">
  
Your Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Message: <textarea name="message"></textarea>
<input type="submit" value="Submit">
</form>

GET Method in HTML Form:-
=========================
<form method="get" name="mail" action="mailpage.jsp">
  
Your Name: <input type="text" name="name">
Email Address: <input type="text" name="email">
Message: <textarea name="message"></textarea>
<input type="submit" value="Submit">
</form>
using System.Net.Mail;
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress("From mail address");
mailMessage.To.Add(new MailAddress("To Email Address "));
mailMessage.CC.Add(new MailAddress("CC Email Address "));
mailMessage.Bcc.Add(new MailAddress("BCC Email Address "));
mailMessage.Subject = "Subject";
mailMessage.Body = "Body of the Message ";
mailMessage.IsBodyHtml = true;//to send mail in html or not
SmtpClient smtpClient = new SmtpClient("smtp server host", 25);
smtpClient.EnableSsl = false; //True or False depends on SSL Require or not
smtpClient.UseDefaultCredentials = true ;
Object mailState = mailMessage;

//this code adds event handler to notify that mail is sent or not
smtpClient.SendCompleted += new SendCompletedEventHandler(smtpClient_SendCompleted);
try
{
smtpClient.SendAsync(mailMessage, mailState);
}
catch (Exception ex)
{
Response.Write(ex.Message);
Response.Write(ex.StackTrace);
}
->Following is a code for event handler
void smtpClient_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
MailMessage mailMessage = e.UserState as MailMessage;
if (!e.Cancelled && e.Error != null)
{
Response.Write("Email sent successfully");
}
else
{
Response.Write(e.Error.Message);
Response.Write(e.Error.StackTrace);
}
}

Add a comment
Know the answer?
Add Answer to:
How can I simply set up a SMTP in my personal html code? Example code would...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • HTML Canvas: I have given my small html + js mix code below. By this program-...

    HTML Canvas: I have given my small html + js mix code below. By this program- I can just draw line, but after drawing any image I want to save the "image " on my desktop. I understand, I have to make a "button" to SAVE it and later if I want to load the picture, then I have to make a button on the webpage to "LOAD". But I am unable to understand the function I should write for...

  • PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head>...

    PHP Can't get my code to work, what am I doing wrong? <!DOCTYPE html> <html> <head> <script> </script> </head> <body> <h2>Temperature Conversion Table</h2> <h4>Enter a starting value in degrees Fahrenheit and an increment value.</h4> <form name="myTemp" onsubmit="convertCelcius()" method="post"> <input type="text" name="temperature"> Enter an value in degrees Fahrenheit<br><br> <input type="radio" name="degIncrement" id="degIncrement5"> Convert in increment in 5 degrees<br> <input type="radio" name="degIncrement" id="degIncrement10"> Convert in increment in 10 degrees <br/><br/><input type="submit" value="Submit"> </form> <?php if( $_POST["temperature"] || $_POST["degincrement"] ) { //get he...

  • In my HTML and CSS project I want to apply a picture to the bottom right...

    In my HTML and CSS project I want to apply a picture to the bottom right corner... can I get help on how to do this (ie code and a good example)? Here is a sample of my css code: CSS: html {     background: url(jb_back2.png) center center / cover no-repeat fixed; } body {     max-width: 960px;     margin-left: auto;     margin-right: auto;     /*display: -webkit-box;     display: -moz-box;     display: -ms-flexbox;     display: -webkit-flex;*/     display: flex;    ...

  • can i get an example of a java code using a class and bulit in methods...

    can i get an example of a java code using a class and bulit in methods inculding everything else in the picture 20% Control structures decision: if. else if.... Else switch ... case (optional) repetition (at least 2 iterations) while, do...while for 20% Classes (at least 2 classes) 10% Methods (at least 2 methods) user-defined and/or built-in methods 10% Arrays (at least 1 set of array) 20% User Interface Menu like starting point User friendliness Error free

  • can i get an example of a java code using a class and user defined menthod...

    can i get an example of a java code using a class and user defined menthod with everything else listed in the picture 20% Control structures decision: if. else if.... Else switch ... case (optional) repetition (at least 2 iterations) while, do...while for 20% Classes (at least 2 classes) 10% Methods (at least 2 methods) user-defined and/or built-in methods 10% Arrays (at least 1 set of array) 20% User Interface Menu like starting point User friendliness Error free

  • Im stuck. can someone please show me code on how i can make text appear on...

    Im stuck. can someone please show me code on how i can make text appear on html canvas. i want to create a form where someone for example put their name and when submit button is clicked on the form it appear on the canvas. i am using html javascript. please show code for javascript, canvas, and html. please let me know if im not making sense. Thank you

  • Hey Guys I am doing a project and need some help with code in HTML and...

    Hey Guys I am doing a project and need some help with code in HTML and PHP. I need a form made in HTML that can be sent to a specific email through PHP. For some reason the info is not getting sent to my email, even though it says that it was sent. I have some source code here: <?php if(isset($_POST['submit'])) { $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $email = mail('MY_EMAIL', $subject, $message,...

  • HTML Web Page project: Need help to create a web page exactly as the example below...

    HTML Web Page project: Need help to create a web page exactly as the example below using HTML. I need the source code. Page 1 of CA272 Midterm Welcome to your name's CA272 Midterm Text In this class, I learned how to... 1. create an X)HTML web page, where I can 2. change the size of my font, 3. change the color of my fonts, 4. change my font style, 5. and change the background color of my web page....

  • How can I convert $num_rows to PDO? See errors below code ** (PHP, MySQL, HTML) $sql...

    How can I convert $num_rows to PDO? See errors below code ** (PHP, MySQL, HTML) $sql = "SELECT testN, testG from testTab";    $res = $db -> query($sql);    ** if ($res-> $num_rows >0)    {        while($row = $result-> fetch_assoc())        {            echo "". $row["testN"] ."". $row["testG"]. "";            if($row['testG'] < 60)            {            echo "". "F" ."";            }            elseif($row['testG'] >= 60 and $row['testG']<=69)            {                echo "". "D" ."";            }        }        echo "";     } else    {        echo("0 Result");           } ** Notice: Undefined variable: result...

  • How can I get my Python code to check to make sure there are no ships...

    How can I get my Python code to check to make sure there are no ships overlapping in my Battleship code? I am having a really hard time with a game of battleship that I have due for class. Each time I run my code, It will print the ships on the board but it will at times overlap them. I know I have to use some kind of nested if statements but I just don't get how or where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT