利用email.net設定網路代理程式發郵件

來源:互聯網
上載者:User

標籤:c#   .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 totarget.Host = hostBox.Text;//TCP port for connectiontarget.Port = (ushort)portNum.Value;//Username to login to the SMTP servertarget.Username = loginBox.Text;//Password to login to the SMTP servertarget.Password = passwordBox.Text;//Configure proxytarget.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 messageSmtpMessage message = new SmtpMessage(new EmailAddress(fromBox.Text),//Source addressaddressCollection,//Address of the recipientsubjectBox.Text,//Message subjectmessageBox.Text //Message text);SendResult result = target.SendOne(message);//Send messageif (result.IsSuccessful){MessageBox.Show("Message sent successful!");}else{MessageBox.Show("Message sending failed!");}}}}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.