I have a gmail id for my school's account. once I give that id, it will direct me to my school's website where i enter my username and password.
Now I tried to create an application using Visual Studio 17 where I can send mail directly using an app. But it is not getting through. My id passwords do not match probably I guess. Why I'm telling this is, when I tried with my other gmail id and password it worked. But since this gmail id is with my school id, it is not going through.
this is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
namespace mail
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label2_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
String Subject = "ATSO " +checkBox1.Text + " Assesment " + radioButton1.Text;
String st = "This is a confirmation mail for your appointment with Daminna on" + dateTimePicker1.Text + " You do not have to carry your laptop";
//MailMessage msg = new MailMessage("krishchan1994@gmail.com", textBox1.Text, "TEST TEST TEST", textBox2.Text);
SmtpClient mail = new SmtpClient("smtp.gmail.com", 587);
mail.EnableSsl = true;
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.UseDefaultCredentials = false;
mail.Credentials = new NetworkCredential("krishnan.chandran@csueastbay.edu", "mypassword");
MailMessage msg = new MailMessage();
msg.To.Add(textBox1.Text);
msg.From = new MailAddress("krishnan.chandran@csueastbay.edu");
msg.Subject = "ATSO Assessment Confirmation";
msg.Body = st;
mail.Send(msg);
MessageBox.Show("Message sent Successfully XD .!");
}
catch(Exception ex)
{
MessageBox.Show("FAIL");
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
}
}
This is my gmail login: IF you see I select one account there.
Here, again i enter my school's ID and Password.
So after all this, I get confused with the mail id and the smtp related to it. I have a school id and also a gmail id related to it. Now Should I enter which one in my code.