18 个解决方案
#1
应该是获取网页内容后拼接字符串发送的吧……
#2
try {
WebClient client = new WebClient();
Byte[] pageData = client.DownloadData("http://www.baidu.com");
string pageHtml = Encoding.ASCII.GetString(pageData);
//pageHtml就是百度生产的源文件,可以把这个当做邮件内容发送出去
}
catch (WebException webEx) {
if(webEx.Status == WebExceptionStatus.ConnectFailure) {
Console.WriteLine("");
}
}
#3
提供你一个发送Email的函数,测试可行。
你所说的,只是Email的body是HTML而已。
注意这句话:msg.BodyFormat = System.Web.Mail.MailFormat.Html;
public bool SendToEmail(string ToEmailName, string TheSubject, string Thebody)
{
try
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = "xxx@xxx.com";
msg.To = ToEmailName;
msg.Subject = TheSubject;
msg.Body = Thebody;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
string username = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
string emailSmtp = System.Configuration.ConfigurationManager.AppSettings["EmailSMTP"];
if (String.IsNullOrEmpty(username) ||
String.IsNullOrEmpty(password) ||
String.IsNullOrEmpty(emailSmtp))
{
throw new Exception("Error username or password for Email,check the config file of [EmailUserName] and [EmailPassword] and [EmailSMTP]!");
}
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
System.Web.Mail.SmtpMail.SmtpServer = emailSmtp;
System.Web.Mail.SmtpMail.Send(msg);
return true;
}
catch
{
return false;
}
}
你所说的,只是Email的body是HTML而已。
注意这句话:msg.BodyFormat = System.Web.Mail.MailFormat.Html;
public bool SendToEmail(string ToEmailName, string TheSubject, string Thebody)
{
try
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = "xxx@xxx.com";
msg.To = ToEmailName;
msg.Subject = TheSubject;
msg.Body = Thebody;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
string username = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
string emailSmtp = System.Configuration.ConfigurationManager.AppSettings["EmailSMTP"];
if (String.IsNullOrEmpty(username) ||
String.IsNullOrEmpty(password) ||
String.IsNullOrEmpty(emailSmtp))
{
throw new Exception("Error username or password for Email,check the config file of [EmailUserName] and [EmailPassword] and [EmailSMTP]!");
}
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
System.Web.Mail.SmtpMail.SmtpServer = emailSmtp;
System.Web.Mail.SmtpMail.Send(msg);
return true;
}
catch
{
return false;
}
}
#4
就是将字符串拼接成HTML就可以了,基本大部分的邮件客户端都支持
#5
关注
#6
3,4楼说的对!!
#7
#8
三四楼说得有道理
#9
发送之后都是?????????
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
这两个都不行
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
这两个都不行
#10
引用命名空间using System.Web.Mail;
using System.Text.RegularExpressions;
#region 将指定的网页发送Web邮件
/// <summary>
/// 将指定的网页发送Web邮件
/// </summary>
/// <param name="mailFrom">发送邮件地址</param>
/// <param name="mailTo">接收邮件地址</param>
/// <param name="mailSubject">邮件主题</param>
/// <param name="mailUrl">发送的HTML也地址</param>
/// <param name="mailFilePath">发送邮件的附件</param>
///<param name="i">发送邮件的方式</param>
/// <returns></returns>
public bool SendWebMail(string mailFrom, string mailTo, string mailSubject, string mailPassWord, string mailUrl, string[] mailFilePath, int i)
{
MailMessage mail = new MailMessage();
mail.From = mailFrom; ;
mail.To = mailTo;
mail.Subject = mailSubject;
mail.BodyFormat = MailFormat.Html;
string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailSmtp[0]); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailPassWord); //set your password here
SmtpMail.SmtpServer = mailSmtp[1].Insert(0, "smtp.");
string[] file = mailFilePath;
foreach (string filePath in file)
{
if (filePath != "")
{
mail.Attachments.Add(new MailAttachment(filePath));
}
}
try
{
WebClient myclient = new WebClient();
byte[] myBytes = myclient.DownloadData(mailUrl);
mail.Body = Encoding.Default.GetString(myBytes);
SmtpMail.Send(mail);
return true;
}
catch
{
return false;
}
}
using System.Text.RegularExpressions;
#region 将指定的网页发送Web邮件
/// <summary>
/// 将指定的网页发送Web邮件
/// </summary>
/// <param name="mailFrom">发送邮件地址</param>
/// <param name="mailTo">接收邮件地址</param>
/// <param name="mailSubject">邮件主题</param>
/// <param name="mailUrl">发送的HTML也地址</param>
/// <param name="mailFilePath">发送邮件的附件</param>
///<param name="i">发送邮件的方式</param>
/// <returns></returns>
public bool SendWebMail(string mailFrom, string mailTo, string mailSubject, string mailPassWord, string mailUrl, string[] mailFilePath, int i)
{
MailMessage mail = new MailMessage();
mail.From = mailFrom; ;
mail.To = mailTo;
mail.Subject = mailSubject;
mail.BodyFormat = MailFormat.Html;
string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailSmtp[0]); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailPassWord); //set your password here
SmtpMail.SmtpServer = mailSmtp[1].Insert(0, "smtp.");
string[] file = mailFilePath;
foreach (string filePath in file)
{
if (filePath != "")
{
mail.Attachments.Add(new MailAttachment(filePath));
}
}
try
{
WebClient myclient = new WebClient();
byte[] myBytes = myclient.DownloadData(mailUrl);
mail.Body = Encoding.Default.GetString(myBytes);
SmtpMail.Send(mail);
return true;
}
catch
{
return false;
}
}
#12
正解了..
#13
关注。。。
#14
来晚了,学习下
#15
学习下,
#16
学习、、、
#17
关注。。。
#18
学习
#1
应该是获取网页内容后拼接字符串发送的吧……
#2
try {
WebClient client = new WebClient();
Byte[] pageData = client.DownloadData("http://www.baidu.com");
string pageHtml = Encoding.ASCII.GetString(pageData);
//pageHtml就是百度生产的源文件,可以把这个当做邮件内容发送出去
}
catch (WebException webEx) {
if(webEx.Status == WebExceptionStatus.ConnectFailure) {
Console.WriteLine("");
}
}
#3
提供你一个发送Email的函数,测试可行。
你所说的,只是Email的body是HTML而已。
注意这句话:msg.BodyFormat = System.Web.Mail.MailFormat.Html;
public bool SendToEmail(string ToEmailName, string TheSubject, string Thebody)
{
try
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = "xxx@xxx.com";
msg.To = ToEmailName;
msg.Subject = TheSubject;
msg.Body = Thebody;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
string username = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
string emailSmtp = System.Configuration.ConfigurationManager.AppSettings["EmailSMTP"];
if (String.IsNullOrEmpty(username) ||
String.IsNullOrEmpty(password) ||
String.IsNullOrEmpty(emailSmtp))
{
throw new Exception("Error username or password for Email,check the config file of [EmailUserName] and [EmailPassword] and [EmailSMTP]!");
}
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
System.Web.Mail.SmtpMail.SmtpServer = emailSmtp;
System.Web.Mail.SmtpMail.Send(msg);
return true;
}
catch
{
return false;
}
}
你所说的,只是Email的body是HTML而已。
注意这句话:msg.BodyFormat = System.Web.Mail.MailFormat.Html;
public bool SendToEmail(string ToEmailName, string TheSubject, string Thebody)
{
try
{
System.Web.Mail.MailMessage msg = new System.Web.Mail.MailMessage();
msg.From = "xxx@xxx.com";
msg.To = ToEmailName;
msg.Subject = TheSubject;
msg.Body = Thebody;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
string username = System.Configuration.ConfigurationManager.AppSettings["EmailUserName"];
string password = System.Configuration.ConfigurationManager.AppSettings["EmailPassword"];
string emailSmtp = System.Configuration.ConfigurationManager.AppSettings["EmailSMTP"];
if (String.IsNullOrEmpty(username) ||
String.IsNullOrEmpty(password) ||
String.IsNullOrEmpty(emailSmtp))
{
throw new Exception("Error username or password for Email,check the config file of [EmailUserName] and [EmailPassword] and [EmailSMTP]!");
}
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", username);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", "465");
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "1");
System.Web.Mail.SmtpMail.SmtpServer = emailSmtp;
System.Web.Mail.SmtpMail.Send(msg);
return true;
}
catch
{
return false;
}
}
#4
就是将字符串拼接成HTML就可以了,基本大部分的邮件客户端都支持
#5
关注
#6
3,4楼说的对!!
#7
#8
三四楼说得有道理
#9
发送之后都是?????????
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
这两个都不行
msg.BodyEncoding = System.Text.Encoding.UTF8;//System.Text.Encoding.GetEncoding("gb2312");
这两个都不行
#10
引用命名空间using System.Web.Mail;
using System.Text.RegularExpressions;
#region 将指定的网页发送Web邮件
/// <summary>
/// 将指定的网页发送Web邮件
/// </summary>
/// <param name="mailFrom">发送邮件地址</param>
/// <param name="mailTo">接收邮件地址</param>
/// <param name="mailSubject">邮件主题</param>
/// <param name="mailUrl">发送的HTML也地址</param>
/// <param name="mailFilePath">发送邮件的附件</param>
///<param name="i">发送邮件的方式</param>
/// <returns></returns>
public bool SendWebMail(string mailFrom, string mailTo, string mailSubject, string mailPassWord, string mailUrl, string[] mailFilePath, int i)
{
MailMessage mail = new MailMessage();
mail.From = mailFrom; ;
mail.To = mailTo;
mail.Subject = mailSubject;
mail.BodyFormat = MailFormat.Html;
string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailSmtp[0]); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailPassWord); //set your password here
SmtpMail.SmtpServer = mailSmtp[1].Insert(0, "smtp.");
string[] file = mailFilePath;
foreach (string filePath in file)
{
if (filePath != "")
{
mail.Attachments.Add(new MailAttachment(filePath));
}
}
try
{
WebClient myclient = new WebClient();
byte[] myBytes = myclient.DownloadData(mailUrl);
mail.Body = Encoding.Default.GetString(myBytes);
SmtpMail.Send(mail);
return true;
}
catch
{
return false;
}
}
using System.Text.RegularExpressions;
#region 将指定的网页发送Web邮件
/// <summary>
/// 将指定的网页发送Web邮件
/// </summary>
/// <param name="mailFrom">发送邮件地址</param>
/// <param name="mailTo">接收邮件地址</param>
/// <param name="mailSubject">邮件主题</param>
/// <param name="mailUrl">发送的HTML也地址</param>
/// <param name="mailFilePath">发送邮件的附件</param>
///<param name="i">发送邮件的方式</param>
/// <returns></returns>
public bool SendWebMail(string mailFrom, string mailTo, string mailSubject, string mailPassWord, string mailUrl, string[] mailFilePath, int i)
{
MailMessage mail = new MailMessage();
mail.From = mailFrom; ;
mail.To = mailTo;
mail.Subject = mailSubject;
mail.BodyFormat = MailFormat.Html;
string[] mailSmtp = Regex.Split(mailFrom, "@", RegexOptions.IgnoreCase);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mailSmtp[0]); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mailPassWord); //set your password here
SmtpMail.SmtpServer = mailSmtp[1].Insert(0, "smtp.");
string[] file = mailFilePath;
foreach (string filePath in file)
{
if (filePath != "")
{
mail.Attachments.Add(new MailAttachment(filePath));
}
}
try
{
WebClient myclient = new WebClient();
byte[] myBytes = myclient.DownloadData(mailUrl);
mail.Body = Encoding.Default.GetString(myBytes);
SmtpMail.Send(mail);
return true;
}
catch
{
return false;
}
}
#11
#12
正解了..
#13
关注。。。
#14
来晚了,学习下
#15
学习下,
#16
学习、、、
#17
关注。。。
#18
学习