2
Answers

unable to connect to the remote server c# smtp gmail

public string SendMail(string Emailids, string subject, string body)
{
string eroorMessage = string.Empty;
try
{
string hostname = ConfigurationManager.AppSettings["contactHost"];
int portno = Convert.ToInt32(ConfigurationManager.AppSettings["contactPort"]);
string frommailid = ConfigurationManager.AppSettings["contactMail"];
string frompwd = ConfigurationManager.AppSettings["contactPassword"];
var sendlist = Emailids.Split(',');
var Tolen = sendlist.Length;
string to = "";
if (Tolen == 1)
{
to = Emailids.Trim(',');
}
else
{
for (int i = 0; i < Tolen; i++)
{
to = sendlist[i];
}
}
var smptClient = new SmtpClient(hostname, portno)
{
Credentials = new NetworkCredential(frommailid, frompwd),
EnableSsl = true
};
smptClient.Send(frommailid, to, subject, body);
return "scucess";
}
catch (Exception ex)
{
eroorMessage = ex.Message.ToString() + ex.StackTrace.ToString() + ex.InnerException.ToString();
return eroorMessage;
}
}
Answers (2)
1
Manav Pandya
NA 7.1k 24.1k 7y
Hello
 
First of all "migration" is related to code-first , not DB First 
 
There is no migration needed for DB First approach .
 
For code first migration : you should write update-database if your DB have pending changes
To enable migration - automatically write following snippet in configuration.cs file: 
  1. AutomaticMigrationsEnabled = true;    
  2. AutomaticMigrationDataLossAllowed = false;     
Thanks