嗨,差不多有一天,我一直在想出关于从godaddy电子邮件帐户发送电子邮件到gmail帐户的事情。我已经在网上进行了研究,几乎尝试了一切,但没有运气。这就是我到目前为止所做的。
protected void generateEmail(){
MailMessage mail = new MailMessage ();
mail.From = new System.Net.Mail.MailAddress ("contact@company.com");
// The important part -- configuring the SMTP client
SmtpClient smtp = new SmtpClient ();
smtp.Port = 465; // [1] You can try with 465 also, I always used 587 and got success
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network; // [2] Added this
smtp.UseDefaultCredentials = false; // [3] Changed this
smtp.Credentials = new NetworkCredential ("contact@company.com", "password123!"); // [4] Added this. Note, first parameter is Email Address of the sender and the next parameter is the password.
smtp.Host = "relay-hosting.secureserver.net";
//recipient address
mail.To.Add (new MailAddress ("test@gmail.com"));
mail.To.Add (new MailAddress ("testagain@gmail.com"));
//Formatted mail body
mail.IsBodyHtml = true;
string st = "This is a Test Message";
mail.Body = st;
smtp.Send (mail);
}
任何人都可以帮助我吗?会很感激任何人..
答案 0 :(得分:0)
protected void generateEmail()
{
//Create the msg object to be sent
MailMessage msg = new MailMessage();
//Add your email address to the recipients
msg.To.Add("whereEmailWillBeSent@gmail.com");
//Configure the address we are sending the mail from
MailAddress address = new MailAddress("mail@company.com");
msg.From = address;
msg.Subject ="Hi this is mail from company";
msg.Body = "Your Message";
SmtpClient client = new SmtpClient();
//for Godaddy
client.Host = "relay-hosting.secureserver.net";
client.Port = 25;
client.EnableSsl = false;
client.UseDefaultCredentials = false;
//Send the msg
client.Send(msg);
//Display some feedback to the user to let them know it was sent
}
}