EMAIL PROGRAMMING
DAY- 02\06\2025
Ø EMAIL PROGRAMMING (MAILPROG.ASPX):-
1. Add net.email programming.
2. Include net.mail libraries .
3. USING SYSTEM.NET.MAIL
4. THERE ARE TWO OBJECT WHICH ARE USED IN
i. MailMessage
ii. SmtpClient
1. MailMessage object:- set the mail property(to,from,sub,boby).
2. SmtpClient:- smtpclient object is used to check credential
Types of credential
a. System credential :-anytypes of devices
b. Any types of document :- etc adharcard.
c. Network credential:- anytype of online application.
3.
v Types of gmail password :-
1. User password created by the user .
2. App secure password:- communicated to code environment .
Ø LET SEE HOW TO SET THE FORMAT OF MAIL .
MailMessObject.IsBodyHtml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class MAILPROG : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// step 1 created maill message obj
MailMessage msg = new MailMessage();
//step2
msg.To.Add(TextBox1.Text);
//msg.From = new MailAddress("your mailid");
msg.From = new MailAddress("rahulthosar517@gmail.com");
msg.Subject = "TESTING MAIL ";
msg.Body = " AJJ PROTEIN LENE KA PLAN BANA LETE";
// step 3 set the mail mess format
msg.IsBodyHtml = true;
//step 4 create smtp object
SmtpClient stp = new SmtpClient();
//step 5 set the host
stp.Host = "smtp.gmail.com";
//step 6 set the port(outgoing)
stp.Port = 587;
// STEP 7 SET PASSWORD
// syntax stp.Credentials = new System.Net.NetworkCredential("rahulthosar517@gmail.com","app secure password");
stp.Credentials = new System.Net.NetworkCredential("rahulthosar517@gmail.com", "");
//set ssl (server security license) (domain security sttps)
stp.EnableSsl = true;
// step 8 send your mail
stp.Send(msg);
//
}
}
For the email gridview task ass two lib using system.text & using system.io;
Email error
error System.Web.HttpException: 'Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.'
Soltuion for above error is
public override void VerifyRenderingInServerForm(Control control)
{
/* Verifies that the control is rendered */
}
if after this also not solved then add this in html page tag
EnableEventValidation="false"
____________________________________________________________________________________________
�� Step-by-Step:
1. Go to your Google Account:
o https://myaccount.google.com
2. Navigate to Security:
o In the left-hand menu, click on “Security”.
3. Enable 2-Step Verification (if not done already):
o Under "Signing in to Google", click on 2-Step Verification.
o Follow the prompts to enable it.
4. Access App Passwords:
o After enabling 2-Step Verification, go back to Security.
o Click App passwords (you may be prompted to re-enter your password).
§ URL: https://myaccount.google.com/apppasswords
5. Generate App Password:
o Under "Select app", choose Mail.
o Under "Select device", choose Other (Custom name) → Enter MyApp or any relevant name.
o Click Generate.
6. Copy the Password:
o You’ll see a 16-character password. Copy it and use it instead of your regular Gmail password in your application (e.g., SMTP setup in ASP.NET).
App secure password vpho brbk iyyh hxbw
Comments
Post a Comment