如何使用smtp c#从电子邮件地址发送邮件#

时间:2014-04-08 06:43:02

标签: c#-3.0

我们希望使用电子邮件地址而不是smtp电子邮件地址发送电子邮件... 我尝试发送邮件,其中来自电子邮件地址和smtp验证的电子邮件地址是不同的。 它给了我错误。

1 个答案:

答案 0 :(得分:0)

您可以根据以下代码进行操作。希望它有所帮助

MailMessage mailMessage = new MailMessage();
mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress("sender@domain.com", "Subject"); // You can try changing this to the email address you want
mailMessage.ReplyToList.Add("sender@domain.com"); // Here you can add reply to
mailMessage.Subject = "ENQUIRY - " + DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss");
mailMessage.Body = ""; // The body of email
SmtpClient smtpClient = new SmtpClient("mail.company-domain.com");
smtpClient.Credentials = new NetworkCredential("username", "password");
smtpClient.Port = 587; // We used this port instead of port 25
smtpClient.Send(mailMessage);