none
模拟exchange在sharepoint server 2010发送邮件 RRS feed

  • 问题

  • 所要实现的功能:进行邮件的迁移.

    实现过程中要了解的几个问题:

    1.我的配置环境sharepoint server 2010,开发环境用visual studio 2010

    2.exchange有一个邮件接口,我想在visual studio中编写代码实现这个功能。

    希望各位能帮我看看这个问题,说一下里面的实现原理,给我个例子我参考一下。链接也行。谢谢。

    2012年1月14日 3:47

全部回复

  • Hi virus,

    如果你是想通过开发来发送邮件,你只需要获取下面一exchage的一些字段(用户名,密码,邮件服务器的地址等等)就可以了 .下面是我曾经写的发送邮件的一个类。你可以比较一下。

    public class Common
        {
            private string userName;
            private string password;
            private string mailServer;
            private string sendMail;
            private string ccMail;

            public Common()
            {
                userName = RSBLL.GetString("MailUser");//MailUser等都是配置在资源文件中,你可以先死。直接用字符串就行了。
                password = RSBLL.GetString("MailPassword");
                mailServer = RSBLL.GetString("MailServer");
                sendMail = RSBLL.GetString("MailSender");
                ccMail = RSBLL.GetString("MailCC");
            }
            /// <summary>
            /// Public Send mail function
            /// </summary>
            /// <param name="receiveMail">Send address</param>
            /// <param name="cc">cc addresss,can bu null</param>
            /// <param name="subject">Subject</param>
            /// <param name="body">Content</param>
            /// <param name="attachmentsFilePath">Attachments</param>
            public void SendMail(string receiveMail,string cc,string subject,string body,string[] attachmentsFilePath)
            {
                //object
                    SmtpClient client = new SmtpClient();
                    MailMessage message = new MailMessage();
                try
                {
                   
                    //login to server
                    client.Credentials = new NetworkCredential(userName, password);
                    client.Host = mailServer;
                    //address
                    message.From = new MailAddress(sendMail);
                    message.To.Add(receiveMail);

                    string mailCC = String.Join(",", new string[] { ccMail, cc });
                    string[] mailCCs = mailCC.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                    Regex reg = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
                    foreach (string mail in mailCCs)
                    {
                        if(reg.IsMatch(mail) && mail.ToLower().Contains("cadence"))
                        {
                            message.CC.Add(mail);
                        }
                    }
                   
                    //subject
                    message.Subject = subject;
                    //body
                    message.Body = body;
                    message.IsBodyHtml = false;
                    message.BodyEncoding = Encoding.UTF8;
                    //attachments
                    if (attachmentsFilePath != null)
                    {
                        foreach (string attFile in attachmentsFilePath)
                        {
                            message.Attachments.Add(new Attachment(attFile));
                        }
                    }
                    //send
                    client.Send(message);
                }
                catch (Exception ex){
                    throw ex;
                }
                finally{
                //clear
                message.To.Clear();
                message.CC.Clear();
                message.Attachments.Clear();
                message.Subject = String.Empty;
                message.Body = String.Empty;
                }
            }

            }

     

     

    Thanks,

    Jack

    2012年1月17日 2:10
    版主
  • 谢谢你了。

    还有个问题能否在回答我一下

    在exchange中一个功能就是管理员模拟别人发邮件(比如a用户有事,但是a用户要给b用户发邮件,a用户就委托管理员给b用户发邮件,但是b用户看到的发件地址还是a用户的)

    我想问问

    这个用c#怎么去实现

    2012年2月9日 4:08