using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Mail; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace BTrack { public partial class careers : System.Web.UI.Page { string otp; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Assign_Value(); Session["OTP"] = null; } } private void Assign_Value() { txtname.Text = ""; txtemail1.Text = ""; txtcontact.Text = ""; txtmessage.Text = ""; } public static string GenerateOTP() { Random random = new Random(); int otp = random.Next(1000, 10000); // Generates a number between 1000 and 9999 return otp.ToString(); // Converts the number to a string } public void btnEnterOTP_Click2(object sender, EventArgs e) { otp = GenerateOTP(); Session["otp"] = otp; sendmail(); } public void btnEnterOTP_Click3(object sender, EventArgs e) { string enteredOtp = Txtotp.Text; if (enteredOtp == Session["OTP"].ToString()) { sendmailtosupport(); } else { LblErr.Text = "Invalid OTP"; } } public void btnsubmit_Click(object sender, EventArgs e) { if (Txtotp.ToString() == otp) { } } private void sendmailtosupport() { string email = txtemail1.Text; if (!IsValidEmail(email)) { // Show an error message (e.g., set a label text) LblErr.Text = "Please enter a valid email address."; LblErr.Visible = true; } else { if (FileUpload1.HasFile) { if (!string.IsNullOrEmpty(txtemail1.Text) && !string.IsNullOrEmpty(txtcontact.Text) && !string.IsNullOrEmpty(txtname.Text) && !string.IsNullOrEmpty(txtmessage.Text)) { try { //string otp = GenerateOTP(); // string to = "support@mauli-infotech.co.in"; string to = "sanket.mote@mauli-infotech.co.in"; string from = "donotreply@mauli-infotech.co.in"; string cc = "murlidhar.hambarde@mauli-infotech.co.in"; string cc1 = "urmila.jumare@mauli-infotech.co.in"; SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; // Enable SSL/TLS encryption // Gmail account credentials string gmailUsername = "donotreply@mauli-infotech.co.in"; string gmailPassword = "kofh lfmm gibd cfnm"; // Authenticate with Gmail client.Credentials = new NetworkCredential(gmailUsername, gmailPassword); string msg = ""; msg += "Applicant Name : " + txtname.Text + "\n"; msg += "Email ID : " + txtemail1.Text + "\n"; // msg += "Subject : " + subject.Text + ""; msg += "Message : " + txtmessage.Text + "\n"; // Create a MailMessage object MailMessage message = new MailMessage(from, to); message.Subject = "Resume From Mauli-Infotech (OPC) Pvt.Ltd. Website"; message.Body = "" + msg.ToString() + ""; message.CC.Add(cc); message.CC.Add(cc1); // Get the file name and extension string fileName = Path.GetFileName(FileUpload1.FileName); //Attach the file to the email Attachment attachment = new Attachment(FileUpload1.FileContent, fileName); message.Attachments.Add(attachment); client.Send(message); Assign_Value(); Session["OTP"] = null; Response.Redirect("thanku.aspx"); } catch (Exception ex) { } } else { LblErr.Text = "Please select PDF"; } } } } private bool IsValidEmail(string email) { if (string.IsNullOrEmpty(email)) { return false; // Email is null or empty } // Regular expression for validating email format string emailPattern = @"^[^\s@]+@[^\s@]+\.[^\s@]+$"; return Regex.IsMatch(email, emailPattern); } private void sendmail() { string email = txtemail1.Text; if (!IsValidEmail(email)) { // Show an error message (e.g., set a label text) LblErr.Text = "Please enter a valid email address."; LblErr.Visible = true; } else { if (!string.IsNullOrEmpty(txtemail1.Text) && !string.IsNullOrEmpty(txtcontact.Text) && !string.IsNullOrEmpty(txtname.Text) && !string.IsNullOrEmpty(txtmessage.Text)) { try { //string path = @"C:/CHS/CHSPWD.txt"; // LIVE //string path = @"C:/CHSQAT/CHSPWD.txt";//QAT //string pass=""; //string path = @"D:/MI_Applications/CHS/CHSPWD.txt";//Live or local ////string path = @"D:/MI_Applications/CHSQAT/CHSPWD.txt";//QAT //if (File.Exists(path)) //{ // if (!string.IsNullOrEmpty(path)) // { // string[] readText = File.ReadAllLines(path); // StringBuilder strbuild = new StringBuilder(); // foreach (string s in readText) // { // strbuild.Append(s); // } // pass = strbuild.ToString(); // } //} //else //{ // pass = "chs"; //} string mail = txtemail1.Text; string to = mail; string from = "donotreply@mauli-infotech.co.in"; string cc1 = "urmila.jumare@mauli-infotech.co.in"; SmtpClient client = new SmtpClient("smtp.rediffmailpro.com", 587) { EnableSsl = true, Credentials = new NetworkCredential("donotreply@mauli-infotech.co.in", "Don#Mauli$005") // Replace with secure handling }; // Generate or retrieve the OTP string otp = GenerateOTP(); // Ensure this method is defined and returns a string Session["otp"] = otp; // Store OTP in session // Create the message body string msg = "Welcome to Mauli Infotech (OPC) Pvt. Ltd,'" + txtname + "'\n\n" + "You are receiving this email because you are verifying your profile on Mauli Infotech (OPC) Pvt. Ltd. " + "Please enter '" + otp + "' this OTP on the Mauli Infotech (OPC) Pvt. Ltd to verify your email address.\n\n" + "Best regards,\n"; // Create and configure the MailMessage MailMessage message = new MailMessage(from, to) { Subject = "OTP Verification", Body = msg }; message.CC.Add(cc1); // Send the email client.Send(message); // Set focus to the OTP textbox Txtotp.Focus(); otpMessage.Visible = true; otpdiv.Visible = true; upload.Visible = true; } catch (Exception ex) { // Log or handle the error (e.g., show a message to the user) LblErr.Text = "An error occurred while sending the email: " + ex.Message; } } else { // Handle the case where required fields are empty LblErr.Text = "Please fill in all fields."; } } } // Check that all required fields are filled } }