我正在找esmtp发送组建,谢谢了:)

解决方案 »

  1.   

    我也做了一个(wakimail),谁想试试:www.aspxcontrol.com
      

  2.   

    我看了一下源码,我很奇怪为什么楼主不用SmtpMail和MailMessage类来发送而是自己写了一部分smtp协议。如果是为了通过smtp验证的话,可以为MailMessage设定一些属性来完成这个功能。
      

  3.   

    可以为MailMessage设定一些属性来完成这个功能?
    这个应该怎么做?能举个例子么?
      

  4.   

    using System.Web.Mail;
    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 );
    }
      

  5.   

    其实就是cdo的一些configration属性,可以在msdn里面差到的
      

  6.   

    这里也有一个:
    http://www.stargeek.com/item/26942.html
      

  7.   

    这种方法必须可连接外网才行吗?
    如果是公司内部网,与Internet没有相连,可以么?
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "super_secret"); //set your password here
    这样的方法还可以用?
      

  8.   

    可以的,http://schemas.microsoft.com/cdo/configuration/sendpassword这个不是一个网站,只是配置的名称而已。你可以测试
      

  9.   

    测试OK!
    msdn上我怎么没找到呢?厉害厉害!解决我一个大问题,以前都是用ASPMAIL组件的,现在直接用系统带的就可以啦,哈哈!
      

  10.   

    我也写了一个。大家共同研究把
    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(); }
      

  11.   

    //需求
    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(),""});
    }
    }
    }
    }
    }
      

  12.   

    我用最简单的方法为何有错误:<% @ Page Language="c#" %>
    <% @ 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>
      

  13.   

    我在使用时,当内容中含有HMTL代码时,程序会报错。
    不知是怎么回事