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

      最近在做一个项目,客户的内部网络需要设置代理才能收发邮件,本来一个简单的东西突然变得复杂了,在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!");
			}

		}
	}
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

turbocc

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值