I used the code below to send email, but only sucessfully sent from gmail to other email address.
I changed host and port, but failed.How can I use other email to send?
private string SendMail(string from, string fromname, string to, string subject, string body, string username, string password, string server)
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(from, fromname);
mail.To.Add(to);
mail.Subject = subject;
mail.Body = body;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential(username, password);
smtp.EnableSsl = true;
smtp.Send(mail);
return "send ok";
}
catch (Exception exp)
{
return exp.Message;
}
}
protected void btnConfirm_Click(object sender, EventArgs e)
{
SendMail("xxx@gmail.com", "Lucy", "xxxx@gmail.com", "text", "this is a test email", "xxx@gmail.com", "xxx", "smtp.gmail.com");
}
I changed host = "smtp.sina.com.cn" or "smtp.sina.com", port = 25. But cannot send email.And nothing in the spam. In the future, I will use some companies's email address to send, so now I need to know what is the way send email from any email. Thank you.