Friday 31 August 2018

MailCoding-WithAttachment


Add the namespace

using System.Net;
using System.Net.Mail;


Add this code in your button click

        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("athi.litztech@gmail.com", "MailCoding-Server");//mail sending from
        msg.To.Add("athirarajinesh@gmail.com");//mail sending to. If you want to add multiple to address separate with comma.
        msg.Subject = "MailCoding-Server";
        msg.Body = "Mail coding for sending mail in server";
        Attachment data = new Attachment(Server.MapPath("~/TechWorld - @h!.html")); // your path may look like Server.MapPath("~/Filepath.pdf") 
        msg.Attachments.Add(data);
        msg.Priority = MailPriority.High;//to set the priority of mail
        msg.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net", 25);
        smtp.Send(msg);

Then you will be able to send the mail from your account and can be recieved.



Thursday 30 August 2018

MailCoding-Server


Add the namespace

using System.Net;
using System.Net.Mail;


Add this code in your button click

        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("athi.litztech@gmail.com", "MailCoding-Server");//mail sending from
        msg.To.Add("athirarajinesh@gmail.com");//mail sending to. If you want to add multiple to address separate with comma.
        msg.Subject = "MailCoding-Server";
        msg.Body = "Mail coding for sending mail in server";
        msg.Priority = MailPriority.High;//to set the priority of mail
        msg.IsBodyHtml = true;
        SmtpClient smtp = new SmtpClient("relay-hosting.secureserver.net", 25);
        smtp.Send(msg);

Then you will be able to send the mail from your account and can be recieved.


ComparisonOfString


Add this code in your button click
       
        string string1 = Convert.ToString(txtString1.Text);//assign the value in the textbox to a string variable.
        string string2 = Convert.ToString(txtString2.Text);
        if(string1 == string2)//compare the string you enter
        {
            Response.Write("<script> alert ('String 1 and 2 are Same')</script>");
        }
        else
        {
            Response.Write("<script> alert ('String 1 and 2 are not Same')</script>");
        }
        txtString1.Text = "";
        txtString2.Text = "";

Tuesday 28 August 2018

MailCoding-Local


Add the Namespace

using System.Net;
using System.Net.Mail;


Add this code in your button click

           var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential("athirarajinesh@gmail.com", "password")//your mail id and password.
         
        };
                MailMessage m = new MailMessage();
                m.IsBodyHtml = true;
                m.To.Add("athi.litztech@gmail.com");//mail sending to. If you want to add multiple to address separate with comma.
                m.Bcc.Add("bcc.litztech@gmail.com");//attach a bcc copy
                m.CC.Add("cc.litztech@gmail.com");//attach a cc copy
                m.From = new MailAddress("athirarajinesh@gmail.com");//mail sending from
                m.Subject = "MailCoding-Local";
                m.Body = "Mail coding for sending mail in local host";
                m.IsBodyHtml = true;
                smtp.Send(m);

If you are using your mail for the first time then it will show an SMTP error.


You can solve this in your gmail settings.

To help keep Google Accounts through work, school, or other groups more secure, we block some less secure apps from using them. If you have this kind of account, you’ll see a "Password incorrect" error when trying to sign in. If so, you have two options:

  • Option 1: Install a more secure app that uses stronger security measures. All Google products, like Gmail, use the latest security measures.
  • Option 2: Change your settings to allow less secure apps into your account. We don't recommend this option because it can make it easier for someone to break into your account. If you want to allow access anyway, follow these steps:

  1. Go to the Less secure apps section of your Google Account.
  2. Turn on Allow less secure apps. If you don't see this setting, your administrator might have turned off less secure app account access.

Then you will be able to send the mail from your account and can be recieved.