Send mail Using Gmail Account

Hi Friends,

Here i am posting a function which help to send a email from gmail account to your customer's account . in which you maintain account details and a complete format of mail .  


private void Email_User(string Account_No, string Email, string userName)
        {
            // Here Account_No is the New Account No that you what to send
           //Email is a email address of that person whom you want to send mail
          // userName is the name of that person
            try
            {
                string mail_id = Email;
                MailMessage mm = new MailMessage("dummy@gmail.com", mail_id);
                mm.Subject = "Successful Account Registration";
                mm.Body = "Dear " + userName + "," + "\n" + "Your registration is NOT yet complete! You must login to your account to activate it and complete your registration!" + "\n" + "" + "\n" + "===========================================" + "\n\n\n" + "Your  Account account number: " + Account_No + " \n\n\n" + "============================================" + "\n\n" + "Reminder: You must login to your account in order to activate it." + "\n\n" + "For inqueries and support please use our contact form." + "\n\n" + "Thank you." + "\n\n" + "===========================================" + "\n" + "Keep your account secure by following these simple rules:" + "\n" + "Do NOT click on any links!" + "\n" + "We will always address you by your first name." + "\n" + "We will never send you attached files or ask you to update your login information." + "\n" + "Contact us if you are unsure about an email you received." + "\n" + "============================================";
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = "dummy@gmail.com ";//Sender mailid
                NetworkCred.Password = "dummy123";//Sender Mail password
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587;
                smtp.Send(mm);
               
            }
            catch (Exception ex)
            {
            }
        }

This Email Should be look like this 

Regards ,
Rajesh

1 comment: