当前位置: 代码迷 >> ASP.NET >> 用ASP.NET1.1 连接microsoft online services 通过OUTLOOK来发信解决方法
  详细解决方案

用ASP.NET1.1 连接microsoft online services 通过OUTLOOK来发信解决方法

热度:2396   发布时间:2013-02-25 00:00:00.0
用ASP.NET1.1 连接microsoft online services 通过OUTLOOK来发信
大家好,不知道有没有大侠做过 【用ASP.NET1.1 连接microsoft online services 通过OUTLOOK来发信】的案例,如果有,能否提供源程序?? 我这边一直都成功不了,原先在OULOOK没有升级成OFFICE ONLINE 之前,通过OUTLOOK是能够发信的,那时用SmtpMail.SmtpServer结合MailMessage就能发信了,但现在邮件服务器使用microsoft online services 后,原有的服务器不用,改用MICROSOFT的代理服务器了,且用PRC通过HTTP与微软的MICROSOFT EXCHANGE SERVER建立连接通信。 现在这事很头疼,请各位赐教!

------解决方案--------------------------------------------------------
有没有发信权限

我前几天做了一个
C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using Microsoft.Office.Interop.Outlook;using System.Net.Mail;using System.Configuration;namespace Zi_OutlookUI{    public class MeetRequest    {        public struct AppointMail        {            public string from;     //发件人邮箱                public string to;        //收件人邮箱;号分隔的一个串                public string fromDisplayName; //发件人姓名                public string subject;  //标题                public string body;     //正文                public string location; //地点                public DateTime sTime;  //开始时间                public DateTime eTime;  //结束时间        }        public static void SendAppointMail(AppointMail mail)        {            MailMessage msg = new MailMessage();            MailAddressCollection attendeeList = new MailAddressCollection();            string[] sendTo = mail.to.Split(';');            foreach (string temp in sendTo)            {                if (temp.Trim().Length > 3)                {                    msg.Bcc.Add(temp);                    attendeeList.Add(temp);                }            }            //  Set up the different mime types contained in the message                    System.Net.Mime.ContentType textType = new System.Net.Mime.ContentType("text/plain");            System.Net.Mime.ContentType HTMLType = new System.Net.Mime.ContentType("text/html");            System.Net.Mime.ContentType RTFType = new System.Net.Mime.ContentType("text/rtf");            System.Net.Mime.ContentType calendarType = new System.Net.Mime.ContentType("text/calendar;");            //Add parameters to the calendar header                    calendarType.Parameters.Add("method", "REQUEST");            calendarType.Parameters.Add("name", "meeting.ics");            string bodyText = "test";            AlternateView textView = AlternateView.CreateAlternateViewFromString(bodyText, textType);            msg.AlternateViews.Add(textView);            //create the Body in HTML format                string bodyHTML = "hello";            AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(bodyHTML, HTMLType);            msg.AlternateViews.Add(HTMLView);            //create the Body in VCALENDAR format                    string calDateFormat = "yyyyMMddTHHmmssZ";            string bodyCalendar = "BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US & Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{6}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";            bodyCalendar = string.Format(bodyCalendar,                mail.sTime.ToUniversalTime().ToString(calDateFormat),                mail.eTime.ToUniversalTime().ToString(calDateFormat),                mail.location,                mail.fromDisplayName,                mail.from,                Guid.NewGuid().ToString("B"),                mail.subject, //summary                        mail.body,//正文                        DateTime.Now.ToUniversalTime().ToString(calDateFormat),                attendeeList.ToString(),                mail.body                );            AlternateView calendarView = AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType);            calendarView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;            msg.AlternateViews.Add(calendarView);            //  Adress the message                    msg.From = new MailAddress(mail.from, mail.fromDisplayName);            msg.IsBodyHtml = true;            SmtpClient smtpclnt = new SmtpClient();            smtpclnt.UseDefaultCredentials = true;            smtpclnt.Credentials = new System.Net.NetworkCredential("帐号", "密码");            smtpclnt.Host = "smtp.163.com";            smtpclnt.Send(msg);        }    }}
  相关解决方案