我正在找esmtp发送组建,谢谢了:)
解决方案 »
- 请问javascript中获取选中的DropDownList的值?
- gridview统计列问题
- UrlRewrite 二级域名重写 无法找到资源
- 如何在Internet下发布ASP.NET写的程序(急!)
- 一个很简单的问题
- 单点登录请求指点
- 在DataGrid里的Edit列,点一下,怎么控制出来的TextBOX的长度
- 用这种方法,如何改变datagrid某列的宽度?代码写在何处?
- ●●●晕死!VS2003打包的程序不能在WIN2000上安装??????????????
- 欢迎大家都来讨论:100分相送
- 请问水晶报表如何用代码实现数据的填充!
- 字符串先HtmlEncode一下,再HtmlDecode一下,有什么用?
这个应该怎么做?能举个例子么?
private void SendMailWithAuth(){
MailMessage mail = new MailMessage();
mail.To = "[email protected]";
mail.From = "[email protected]";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "my_username_here"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here SmtpMail.SmtpServer = "mail.mycompany.com"; //your real server goes here
SmtpMail.Send( mail );
}
http://www.stargeek.com/item/26942.html
如果是公司内部网,与Internet没有相连,可以么?
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
这样的方法还可以用?
msdn上我怎么没找到呢?厉害厉害!解决我一个大问题,以前都是用ASPMAIL组件的,现在直接用系统带的就可以啦,哈哈!
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.IO;
using System.Text;namespace chipserver
{
public class chipserver : System.ServiceProcess.ServiceBase
{
private System.Timers.Timer timer1;
private System.Diagnostics.EventLog eventLog1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public BR.Companys Companys1=new BR.Companys();
public BR.ChipMatchs ChipMatchs1=new BR.ChipMatchs();
public BR.Function Function1 =new BR.Function(); public chipserver()
{
// 该调用是 Windows.Forms 组件设计器所必需的。
InitializeComponent(); // TODO: 在 InitComponent 调用后添加任何初始化
if (!System.Diagnostics.EventLog.SourceExists("MySource"))
{
System.Diagnostics.EventLog.CreateEventSource(
"MySource","MyNewLog");
} } // 进程的主入口点
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// 同一进程中可以运行多个用户服务。若要将
//另一个服务添加到此进程,请更改下行
// 以创建另一个服务对象。例如,
//
// ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new chipserver() }; System.ServiceProcess.ServiceBase.Run(ServicesToRun);
} /// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.timer1 = new System.Timers.Timer();
this.eventLog1 = new System.Diagnostics.EventLog();
((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 360000;
this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
//
// eventLog1
//
this.eventLog1.Log = "MyNewLog";
this.eventLog1.Source = "MySource";
//
// chipserver
//
this.ServiceName = "chipserver";
((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit(); }
DataTable DTevery=new DataTable();
DTevery=ChipMatchs1.GetBuyMatch(int.Parse(DT.Rows[i][0].ToString()));//8
string path = @"c:\Chip_Demand.csv";
// Add some information to the file.
//fs.Write(info, 0, info.Length);
fs=new FileStream(path,FileMode.Create);
StreamWriter sr = new StreamWriter(fs,Encoding.Default);
sr.WriteLine(oneCompany[lang,0]); for(int j=0;j<DTevery.Rows.Count;j++)
{
int gogo=0;
if(j!=0)
{
if(DTevery.Rows[j]["CompName"].ToString()!=DTevery.Rows[j-1]["CompName"].ToString())
{
sr.WriteLine(oneCompany[lang,1]+DTevery.Rows[j][oneCompany[lang,2]].ToString()+oneCompany[lang,3]+DTevery.Rows[j]["FreePhone"].ToString()+oneCompany[lang,4]+DTevery.Rows[j]["Fax"].ToString());
sr.WriteLine (oneCompany[lang,5]);
}
else
{
gogo=1;
}
}
else
{
sr.WriteLine(oneCompany[lang,1]+DTevery.Rows[j][oneCompany[lang,2]].ToString()+oneCompany[lang,3]+DTevery.Rows[j]["FreePhone"].ToString()+oneCompany[lang,4]+DTevery.Rows[j]["Fax"].ToString());
sr.WriteLine (oneCompany[lang,5]);
}
if(gogo!=1)
{
for(int k=0;k<DTevery.Rows.Count;k++)
{
if(DTevery.Rows[j]["CompName"].ToString()==DTevery.Rows[k]["CompName"].ToString())
{
sr.WriteLine (DTevery.Rows[k][0].ToString()+","+DTevery.Rows[k][1].ToString()+","+DTevery.Rows[k][2].ToString()+","+DTevery.Rows[k][3].ToString()+","+DTevery.Rows[k][4].ToString()+","+DTevery.Rows[k][6].ToString());
try
{
if(DTevery.Rows[k]["Partno_D"].ToString()!=DTevery.Rows[k+1]["Partno_D"].ToString() || DTevery.Rows[k]["CompName"].ToString()!=DTevery.Rows[k+1]["CompName"].ToString())
{
sr.WriteLine (oneCompany[lang,6]);
sr.WriteLine (DTevery.Rows[k][7].ToString()+","+DTevery.Rows[k][8].ToString()+","+DTevery.Rows[k][9].ToString()+","+DTevery.Rows[k][10].ToString()+","+DTevery.Rows[k][11].ToString()+","+DTevery.Rows[k][13].ToString());
sr.WriteLine ("");
}
}
catch
{
sr.WriteLine (oneCompany[lang,6]);
sr.WriteLine (DTevery.Rows[k][7].ToString()+","+DTevery.Rows[k][8].ToString()+","+DTevery.Rows[k][9].ToString()+","+DTevery.Rows[k][10].ToString()+","+DTevery.Rows[k][11].ToString()+","+DTevery.Rows[k][13].ToString());
sr.WriteLine ("");
}
}
}
} }
int count=DTevery.Rows.Count;
sr.Close();
fs.Close();
//供应
DTevery=new DataTable();
DTevery=ChipMatchs1.GetSellMatch(int.Parse(DT.Rows[i][0].ToString()));//8
path = @"c:\Chip_Provided.csv";
// Add some information to the file.
//fs.Write(info, 0, info.Length);
fs=new FileStream(path,FileMode.Create); sr = new StreamWriter(fs,Encoding.Default);
sr.WriteLine (oneCompany[lang,7]);
for(int j=0;j<DTevery.Rows.Count;j++)
{
int gogo=0;
if(j!=0)
{
if(DTevery.Rows[j]["CompName"].ToString()!=DTevery.Rows[j-1]["CompName"].ToString())
{
sr.WriteLine(oneCompany[lang,1]+DTevery.Rows[j][oneCompany[lang,2]].ToString()+oneCompany[lang,3]+DTevery.Rows[j]["FreePhone"].ToString()+oneCompany[lang,4]+DTevery.Rows[j]["Fax"].ToString());
sr.WriteLine (oneCompany[lang,5]);
}
else
{
gogo=1;
}
}
else
{
sr.WriteLine(oneCompany[lang,1]+DTevery.Rows[j][oneCompany[lang,2]].ToString()+oneCompany[lang,3]+DTevery.Rows[j]["FreePhone"].ToString()+oneCompany[lang,4]+DTevery.Rows[j]["Fax"].ToString());
sr.WriteLine (oneCompany[lang,5]);
}
if(gogo!=1)
{
for(int k=0;k<DTevery.Rows.Count;k++)
{
if(DTevery.Rows[j]["CompName"].ToString()==DTevery.Rows[k]["CompName"].ToString())
{
sr.WriteLine (DTevery.Rows[k][0].ToString()+","+DTevery.Rows[k][1].ToString()+","+DTevery.Rows[k][2].ToString()+","+DTevery.Rows[k][3].ToString()+","+DTevery.Rows[k][4].ToString()+","+DTevery.Rows[k][6].ToString());
try
{
if(DTevery.Rows[k]["Partno_D"].ToString()!=DTevery.Rows[k+1]["Partno_D"].ToString() || DTevery.Rows[k]["CompName"].ToString()!=DTevery.Rows[k+1]["CompName"].ToString())
{
sr.WriteLine (oneCompany[lang,8]);
sr.WriteLine (DTevery.Rows[k][7].ToString()+","+DTevery.Rows[k][8].ToString()+","+DTevery.Rows[k][9].ToString()+","+DTevery.Rows[k][10].ToString()+","+DTevery.Rows[k][11].ToString()+","+DTevery.Rows[k][13].ToString());
sr.WriteLine ("");
}
}
catch
{
sr.WriteLine (oneCompany[lang,8]);
sr.WriteLine (DTevery.Rows[k][7].ToString()+","+DTevery.Rows[k][8].ToString()+","+DTevery.Rows[k][9].ToString()+","+DTevery.Rows[k][10].ToString()+","+DTevery.Rows[k][11].ToString()+","+DTevery.Rows[k][13].ToString());
sr.WriteLine ("");
}
}
}
} }
sr.Close();
fs.Close();
if(count==0)
{
Function1.SendMail("[email protected]","[email protected]",oneCompany[lang,9],oneCompany[lang,10],"",@"c:\Chip_Provided.csv",true,true,new string[]{DT.Rows[i]["Email"].ToString().Trim(),""});
}
if(DTevery.Rows.Count==0)
{
Function1.SendMail("[email protected]","[email protected]","oneCompany[lang,9]",oneCompany[lang,10],@"c:\Chip_Demand.csv","",true,true,new string[]{DT.Rows[i]["Email"].ToString().Trim(),""});
}
if(count!=0 || DTevery.Rows.Count!=0)
{
Function1.SendMail("[email protected]","[email protected]","oneCompany[lang,9]",oneCompany[lang,10],@"c:\Chip_Demand.csv",@"c:\Chip_Provided.csv",true,true,new string[]{DT.Rows[i]["Email"].ToString().Trim(),""});
}
}
}
}
}
<% @ Import Namespace="System.Web.Mail" %>
<script language="C#" runat="server">
public void sendmail_click(object sender,EventArgs e)
{
string strmailto=tbmailto.Text;
string strmailfrom=tbmailfrom.Text;
string strsubject=tbsubject.Text;
string strmessage=tbmessage.Text;
try
{
sendmail.Visible=false;
SmtpMail.SmtpServer="smtp.tom.com";
SmtpMail.Send(strmailfrom,strmailto,strsubject,strmessage);
tbmailto.Text="";
tbmessage.Text="";
tbsubject.Text="";
labshowmessage.Text="邮件发送至"+strmailto+"成功!";
result.Visible=true;
}
catch(Exception ee)
{
sendmail.Visible=false;
labshowmessage.Text="邮件发送至"+strmailto+"失败!"+ee.ToString();
result.Visible=true;
}
}
</script>
<HTML>
<HEAD>
<title></title>
</HEAD>
<body>
<form runat="server">
<asp:Panel Runat="server" ID="sendmail" Visible="True">
<TABLE>
<TR>
<TD align="center" colSpan="2">发送邮件</TD>
</TR>
<TR>
<TD>发件人:</TD>
<TD>
<asp:TextBox id="tbmailfrom" Runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>收件人</TD>
<TD>
<asp:TextBox id="tbmailto" Runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>主题</TD>
<TD>
<asp:TextBox id="tbsubject" Runat="server"></asp:TextBox></TD>
</TR>
<TR>
<TD>邮件内容</TD>
</TR>
<TR>
<TD align="center" colSpan="2">
<asp:TextBox id="tbmessage" Runat="server" TextMode="MultiLine"></asp:TextBox></TD>
</TR>
<tr>
<td><asp:Button ID="btnsendmail" Runat=server OnClick="sendmail_click" Text="发送"></asp:Button></td></tr>
</TABLE>
</asp:Panel>
<asp:Panel ID="result" Runat="server" Visible="False">
<asp:Label id="labshowmessage" Runat="server"></asp:Label>
</asp:Panel>
</form>
</body>
</HTML>
不知是怎么回事