码迷,mamicode.com
首页 > Web开发 > 详细

利用email.net设置网络代理发邮件

时间:2017-04-19 12:59:42      阅读:386      评论:0      收藏:0      [点我收藏+]

标签:ems   sage   msdn   pie   适合   ons   nbsp   tpm   ddr   

      近期在做一个项目,客户的内部网络须要设置代理才干收发邮件,本来一个简单的东西突然变得复杂了,在baidu搜索了非常久都没找到适合的组件。baidu就像个废物一样,没办法仅仅能去yahoo搜,结果在微软的组件站点上找到了email.net,地址是:http://visualstudiogallery.msdn.microsoft.com/28b96cd4-b755-48a0-b686-9abb7d5607a8。 这个站点还能够找到非常多不错的关于.net的组件。C#开发人员能够多上上。

     通过代理发邮件的代码例如以下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Email.Net.Common;
using Email.Net.Common.Collections;
using Email.Net.Common.Configurations;
using Email.Net.Smtp;

namespace ProxyUsageDemo
{
	public partial class Demo : Form
	{
		public Demo()
		{
			InitializeComponent();
			proxyType.Items.AddRange(new object [] {EProxyType.No, EProxyType.SOCKS5, EProxyType.SOCKS4});
			proxyType.DropDownStyle = ComboBoxStyle.DropDownList;
			proxyType.SelectedIndex = 1;
			proxyType.Refresh();
		}

		private void sendMessage_Click(object sender, EventArgs e)
		{
			//Create and send message using proxy
			//SMTP client settings
			//URL of host to connect to
			target.Host = hostBox.Text;
			//TCP port for connection
			target.Port = (ushort)portNum.Value;
			//Username to login to the SMTP server
			target.Username = loginBox.Text;
			//Password to login to the SMTP server
			target.Password = passwordBox.Text;
			//Configure proxy
			target.ProxyType = (EProxyType)proxyType.SelectedItem;
			target.ProxyHost = proxyHostBox.Text;
			target.ProxyPort =(ushort) proxyPortNum.Value;
			target.ProxyUser = proxyUserBox.Text;
			target.ProxyPassword = proxyPasswordBox.Text;
			//Create address and message 
			EmailAddressCollection addressCollection = new EmailAddressCollection();
			addressCollection.Add(new EmailAddress(toBox.Text));
			//Create message
			SmtpMessage message = new SmtpMessage(
				new EmailAddress(fromBox.Text),//Source address
				addressCollection,//Address of the recipient
				subjectBox.Text,//Message subject
				messageBox.Text //Message text
				);
			SendResult result = target.SendOne(message);//Send message	
			if (result.IsSuccessful)
			{
				MessageBox.Show("Message sent successful!");
			}
			else
			{
				MessageBox.Show("Message sending failed!");
			}

		}
	}
}


利用email.net设置网络代理发邮件

标签:ems   sage   msdn   pie   适合   ons   nbsp   tpm   ddr   

原文地址:http://www.cnblogs.com/yutingliuyl/p/6732762.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!