Click here to Skip to main content
15,916,527 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
whats the code for send email in vb.net
Posted
Updated 26-Nov-11 20:08pm
v2

1 solution

Here is the code in C#

Convert it by youself. Also an adivce. Try and google your query first.


using System.Net.Mail;
using System.Net;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmitt_Click(object sender, EventArgs e)
    {

        MailMessage mail = new MailMessage();
        mail.Subject = "Enquiry";
        mail.Body = "<b>Name :</b>" + txtName.Text + "<br/> +<b>Address:</b>" + txtAddress.Text + "<br/><b>Email-Id :</b>" + txtEmailId.Text  + "<br/><b>city :</b>" + txtCity.Text + "<br/><b>Phone :</b>" + txtPhoneNo.Text + "<br/><b>Organisation:</b>" + txtOrganisation.Text + "<br/><b>Comment:</b>" + txtComment.Text;
        // mail.Body += "<br><b>Password:</b>" + TextBox2.Text;
        // mail.Body += "<br><b>secret Code:</b>" + chi.ToString();
        //the displayed "from" email address 
        mail.From = new System.Net.Mail.MailAddress("abc@gmail.com", "Enquiry From Website");
        mail.IsBodyHtml = true;
        //mail.BodyEncoding = System.Text.Encoding.Unicode; 
        //mail.SubjectEncoding = System.Text.Encoding.Unicode; 
        //Add one or more addresses that will receive the mail 
        mail.To.Add("info@gmail.com");
        //create the credentials 
        NetworkCredential cred = new NetworkCredential("abc@gmail.com", "xyz[what ever the password is]");
        //create the smtp client...these settings are for gmail 
        SmtpClient smtp = new SmtpClient("smtp.gmail.com");
        smtp.UseDefaultCredentials = false;
        smtp.EnableSsl = true;
        //credentials (username, pass of sending account) assigned here 
        smtp.Credentials = cred;
        smtp.Port = 587;
        //let her rip 
        smtp.Send(mail);
        clear();

    }
    private void clear()
    {
        txtComment.Text = "";
        txtEmailId.Text = "";
        txtName.Text = "";
        txtOrganisation.Text = "";
        txtPhoneNo.Text = "";
        txtCity.Text = "";
        txtAddress.Text = "";
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        clear();
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900