需要尽快帮助 - 无法获得C#发送电子邮件 - 简单!尽快帮助 [英] NEED HELP ASAP - Can't Get C# to Send Email - Simple! Help ASAP
本文介绍了需要尽快帮助 - 无法获得C#发送电子邮件 - 简单!尽快帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
internal static Boolean __send_email(String yourEmailHost,String usersEmailAddress, String userMessageSubject, String userMessageBody, String yourEmailAddress, String yourEmailAddressPassword, UInt16 yourEmailProvidersSMTPPortNumber)
{
string smtpAddress = yourEmailHost;
int portNumber = yourEmailProvidersSMTPPortNumber;
bool enableSSL = true;
string emailFrom = "shelbypurcell000@gmail.com";
string password = "";
string emailTo = "shelby.p67@gmail.com";
string subject = userMessageSubject;
string body = userMessageBody;
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(emailFrom);
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.
using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);
return true;
}
}
return false;//Says this is unreachable code
}
推荐答案
您好,请使用此代码。这是我项目中的工作版本。
Hi, use this code. This is working version from my project.
string smtpAddress = "smtp.gmail.com";
int portNumber = 25;
string emailFrom = "shelbypurcell000@gmail.com";
string password = "";
string emailTo = "shelby.p67@gmail.com";
string subject = userMessageSubject;
string body = userMessageBody;
MailMessage objMailMessage = new MailMessage(emailFrom, emailTo, subject, body);
SmtpClient objSmtpClient = new SmtpClient(smtpAddress);
objSmtpClient.Port = portNumber;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.Credentials = new NetworkCredential(emailFrom, password);
objSmtpClient.EnableSsl = true;
objMailMessage.Attachments.Add(new Attachment(Employee.FileLocation));
objSmtpClient.Send(objMailMessage);
这篇关于需要尽快帮助 - 无法获得C#发送电子邮件 - 简单!尽快帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文