Hello! Dev.
i Am working on project and the project is is ASP.net c#,
I want to send Email on signup to user and owner of that site that the demo user create his/her account, and the same thing i use on contact us page, but My email code is working fine on local server, but when i upload my site to live server, no email sending, that code is not working, i didn't face any error on live server and email also not sanded, but that code is working 100% fine on local server.
What I have tried:
What i am tried is below.
This is Email.cs Class
public static bool SendEmail(string toadd, string subject, string msg, string cc = "", string bcc = "", string attachedfile = null)
{
MailMessage message = new MailMessage();
SmtpClient client = new SmtpClient();
try
{
string SendingEmail = "", MailServer = "", SendingPassword = "";
SendingEmail = "myemail.@gmail.com";
MailServer = "smtp.gmail.com";
SendingPassword = "myEmailPassword";
int ServerPort = 587;
message.IsBodyHtml = true;
message.From = new MailAddress(SendingEmail, "Driddle");
message.To.Add(new MailAddress(toadd.ToString()));
if (!string.IsNullOrEmpty(cc))
{
message.CC.Add(new MailAddress(cc.ToString()));
}
if (!string.IsNullOrEmpty(bcc))
{
message.Bcc.Add(new MailAddress(bcc.ToString()));
}
if (attachedfile != null)
{
Attachment attach = null;
string[] attachArr = attachedfile.Split('*');
foreach (string obj in attachArr)
{
attach = new System.Net.Mail.Attachment(obj);
message.Attachments.Add(attach);
}
}
message.Body = msg;
message.Subject = subject;
client.Host = MailServer;
client.Port = ServerPort;
client.EnableSsl = true;
client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential(SendingEmail, SendingPassword);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Send(message);
return true;
}
catch (Exception ex)
{
return false;
}
finally
{
message = null;
client = null;
}
}
This is my contact us page code,This code is working fine on local server Email sended successfully but when i upload this to server, this code didn't send any email and also there is no error on live server data save sucessfully to database but email is not working.
protected void Unnamed_Click(object sender, EventArgs e)
{
using(amazoneEntities db = new amazoneEntities()){
conatactU u = new conatactU();
u.Name = firstName.Text;
u.email = email.Text;
u.subject = phone.Text;
u.message = message.Text;
string Dat = DateTime.Now.ToString("");
u.MessageDate = Convert.ToDateTime(Dat);
u.status1 = "1";
db.conatactUs.Add(u);
db.SaveChanges();
var query = db.contactEmail(email.Text).ToList();
if (query.Count() > 0)
{
string sellerEmail = email.Text;
string subject = phone.Text;
Email.SendEmail(sellerEmail, "Thanks For Contacting Us", "Your Message Received Successfully. You will be answer within 24 hours ,Due to Large amount of queries");
alert.SendEmail(subject, "SMS ALERT", "Some one want to contact us with this subject" + "<br>" + subject + "<br>" + "With this Email Address" + "<br>" + sellerEmail);
}
}
}