白羽
2018-07-25
来源 :网络
阅读 1627
评论 0
摘要:本文将带你了解Exchange服务器之Exchange Web Services简单发送邮件,希望本文对大家学Exchange有所帮助
在网上查找Office365使用EWS简单发邮件的方法时,查到的也不适用,所以自己写一个特别简单的发邮件方法,
当然其他的方法需要大家自己查找,如果我研究EWS下面的内容,我也会实时更新。
首先需要安装EwsManagedApi.msi,然后找到安装后的文件夹下的两个dll。
12345
打开Visual studio 新建Windows 窗体应用程序(也可以是其他的新建
项目),然后引用Microsoft.Exchange.WebServices.dll,下面就是简单的发送邮件代码。
123
using System;
using Microsoft.Exchange.WebServices.Data;
namespace HelloWorld
{
class Form1: Form
{
private void Form1_Load(object sender, EventArgs e)
{
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("你的Office365邮箱地址", "你的Office365邮箱密码");
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("你的Office365邮箱地址", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("收件人的邮箱地址");
email.Subject = "邮件主题";
email.Body = new MessageBody("邮件内容");
email.Send();//发送邮件
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
}
}
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标系统运维之Exchange频道!
喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号