net1.0&2.0发mails

本文提供使用ASP.NET通过两种不同方法发送电子邮件的代码示例。一种方法适用于.NET Framework 2.0,另一种适用于早期版本。示例展示了如何配置SMTP服务器、设置邮件内容及附件,并成功发送邮件。
Imports System
Imports System.Web
Imports System.Web.Mail
Imports System.Net
Imports System.Net.Mail


Partial Class sendmailweb
    Inherits System.Web.UI.Page

    Protected 
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        
'2.0发mail的方法

        
Dim mymail As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage("flash_angle@hotmail.com.cn""yaya_xu@gemtek-ks.com.cn""test""yaya_test")

        
Dim client As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient("mail.gemtek-ks.com.cn")
        client.Credentials 
= New NetworkCredential("yaya_xu""flash_angle")
        client.Send(mymail)
        Response.Write(
"ok")


        
' string file = "e:inetpubwwwrootTest2005AllTestXML estXML.xml";
        ' System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("Test@126.com", "Test@126.com", "text message for you.", "Test Title");
        ' System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(file, System.Net.Mime.MediaTypeNames.Application.Octet);
        ' System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
        ' disposition.CreationDate = System.IO.File.GetCreationTime(file);
        ' disposition.ModificationDate = System.IO.File.GetLastWriteTime(file);
        ' disposition.ReadDate = System.IO.File.GetLastAccessTime(file);
        ' message.Attachments.Add(data);
        'System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(server);
        'client.Credentials = new NetworkCredential("用户名", "密码");
        'client.Send(message);
        'data.Dispose();



    
End Sub

    Protected 
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    
End Sub

    Protected 
Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        
'1.0发mail的方法
        Dim mymail As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage()

        mymail.From 
= "flash_angle@hotmail.com.cn"
        mymail.To 
= "yaya_xu@gemtek-ks.com.cn"
        mymail.Subject 
= "test:"
        mymail.BodyFormat 
= System.Web.Mail.MailFormat.Html
        mymail.Body 
= "test yaya"
        
'  System.Web.Mail.SmtpMail.SmtpServer = "10.4.180.37"



        System.Web.Mail.SmtpMail.Send(mymail)
        
'服务器拒绝了一个或多个收件人地址。服务器响应为: 550 5.7.1 Unable to relay for yaya_xu@gemtek-ks.com.cn
        Response.Write("send ok")
        
'首先说一下SMTP配置。
        '        (1)右键点击“SMTP虚拟服务器”选择“属性”->在“常规”选项卡中设置“IP地址(P)”,我设置的是10.4.180.37。
        '        (2)选择“访问”选项卡,点击“中继”,选上“仅以下列表”(默认是被选上的),点击“添加”,在“单台计算机”中加入10.4.180.37。
        '         提示,如果没有完成(2),则会出现大家常见的一种错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为: 550 5.7.1 Unable to relay yaya_xu@gemtek-ks.com.cn(友情提示一下:错误中的邮件地址有所不同) 然后开始核心代码,其实和方法(一)的差不多。与(一)的主要区别在于:1.SMTP的不同,2.objMailMessage.From中本方法可以随便填写,但是(一)中别随便填写那么利用ASP.NET(C#)发送邮件的核心代码如下:


    
End Sub
End Class
 
import numpy as np from sklearn.datasets import load_iris from operator import itemgetter from collections import defaultdict from sklearn.model_selection import train_test_split import os from collections import Counter def make_Dictionary(root_dir): all_words = [] # 读取所有文件下的数据路径 emails = [os.path.join(root_dir, f) for f in os.listdir(root_dir)] # 依次遍历处理 for mail in emails: with open(mail) as m: for line in m: words = line.split() all_words += words dictionary = Counter(all_words) list_to_remove = list(dictionary) for item in list_to_remove: if not item.isalpha(): del dictionary[item] elif len(item) == 1: del dictionary[item] return dictionary def extract_features(mail_dir, dictionary): """ :param mail_dir: 数据路径 :param dictionary: 数据词典 :return: x,y """ files = [os.path.join(mail_dir, fi) for fi in os.listdir(mail_dir)] features_matrix = np.zeros((len(files), len(dictionary))) train_labels = np.zeros(len(files)) count = 0 docID = 0 for fil in files: with open(fil) as fi: for i, line in enumerate(fi): if i == 2: words = line.split() for word in words: for i, d in enumerate(dictionary): if d[0] == word: wordID = i features_matrix[docID, wordID] = words.count(word) train_labels[docID] = 0 filepathTokens = fil.split('/') lastToken = filepathTokens[len(filepathTokens) - 1] if "spmsg" in lastToken: train_labels[docID] = 1 count = count + 1 docID = docID + 1 return features_matrix, train_labels # 加载训练数据集 TRAIN_DIR = "src/train-mails" # 数据处理 dictionary = make_Dictionary(TRAIN_DIR) # 分割为数据和标签 X_train, y_train = extract_features(TRAIN_DIR, dictionary) # 找到特征feature_index下的特征值feature_value对应的多数类及其误差。 def train_feature_class(x, y_true, feature_index, feature_values): num_class = defaultdict(int) # 统计feature_value下不同类别对应的样例的数目 for sample, y in zip(x, y_true): if sample[feature_index] == feature_values: num_class[y] += 1 # 进行排序,找出最多的类别。按从大到小排列 sorted_num_class = sorted(num_class.items(), key=itemgetter(1), reverse=True) # 获取排在最前面的,也就是多数类 most_frequent_class = sorted_num_class[0][0] # 计算误差个数 error = sum(value_num for class_num, value_num in sorted_num_class if class_num != most_frequent_class) return most_frequent_class, error # 找到某个特征下的所有规则 def train_feature(x, y_true, feature_index): # 获取样本数和特征数 n_sample, n_feature = x.shape assert 0 <= feature_index < n_feature # 获取所有可能值 value = set(x[:, feature_index]) predictors = {} errors = [] # 遍历所有值,找出多数类及误差,保存到errors for current_value in value: most_frequent_class, error = train_feature_class(x, y_true, feature_index, current_value) predictors[current_value] = most_frequent_class errors.append(error) total_error = sum(errors) return predictors, total_error # 找到所有特征下的各特征值的类别。 # 格式就如:{0:({0: 0, 1: 2}, 41)} # 首先为一个字典,字典的键是某个特征,字典的值由一个集合构成,这个集合又是由一个字典和一个值组成,字典的键是特征值,字典的值为类别,最后一个单独的值是错误率。 all_predictors = {feature: train_feature(X_train, y_train, feature) for feature in range(X_train.shape[1])} # 筛选出每个特征下的错误率出来 errors = {feature: error for feature, (mapping, error) in all_predictors.items()} # ********** Begin *********# # one Rule(OneR)算法 best_feature, best_error = # 建立模型 model = # ********** End *********# print(model) 预期输出: {'feature': 0, 'predictor': {0.0: 0.0, 1.0: 0.0, 2.0: 1.0, 3.0: 1.0, 4.0: 0.0, 5.0: 0.0, 6.0: 0.0, 7.0: 0.0, 8.0: 0.0, 9.0: 0.0, 10.0: 0.0, 12.0: 1.0, 14.0: 0.0, 15.0: 0.0, 16.0: 1.0, 17.0: 0.0, 22.0: 1.0, 23.0: 0.0, 26.0: 1.0, 27.0: 1.0, 28.0: 0.0, 31.0: 0.0, 34.0: 1.0, 46.0: 1.0, 63.0: 1.0}}
11-05
client_id = 'dbc8e03a-b00c-46bd-ae65-b683e7707cb0' refresh_token = 'M.C546_BAY.0.U.-CsnnPMkIaj6htKHHWpb8DqvtJrFFAR0fg*7nUMW7H5BT9qUX2TjJsbKEKztSYlxrmRKDZNbn7qK39uudoFMx3ZUHlZpfbz5RPdioIwbQ5aW7WxlhTUd8nv7SKLafDc7jV4ClKUcriLx!ZOW8Gw0o0*74lK1K0jlvWrypzWUhpGanXkeEL4QQWkoXeyfF4iboPfBGhrfvn*t*3CbKnx4N9JTxzlh*oE28JRgQVF51cM1RDjIvc1B!0k5e3srvtF0FCH17jtlc4jBxG7QZ!yV4YpClqOVb057h!9kNAUZvEKZ2yyP03sL42kNxAy2XWlhTVP6V!QYXBqSJ4gJbu7gdiytcPocLTDl1KB8Gp8EylwUZ2gXq1abp4xWp!bdxIUWiOlmTcKyceEf7lomgTyZtBKk$~~~~personalization_id="v1_dZ1RdoxN2MXi09LXqO0+mA=="; __cf_bm=b1H4hcQX_bHfwJVwB63U1jLW6sOIoxlBfr99NBQENqg-1761026322-1.0.1.1-UVKrPeYtIAxch6DFUlnxKk_xTXakJoPfPqZtzU549tzwdlGgwHZoY9ev8WjBkwHfKgNRh6l25brb3k2JrdJwvNrBgV5PyGRLGao5aaSuvMU; ct0=f4019332ca68158078bfe359fb2fe367; dnt=1; client_token="129032-d21de8-OUbDSrnI/hGUPLbSscoF/OxCWUQ4KAowR2sspAOm5/g="; ads_prefs="HBESAAA="; _twitter_sess=BAh7CiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%250ASGFzaHsABjoKQHVzZWR7ADoPY3JlYXRlZF9hdGwrCJsiWQWaAToJdXNlcmwr%250ACQCglkB08x8bOgxjc3JmX2lkIiU5M2JhMDg2M2E2ZTA5OTU3MmVjOTQxMGY5%250AZmI5N2NiYzoHaWQiJWIzOGU1Mjg3NGU5N2E2NTU0ZTFmYjE5NGI1M2MwZDY3--42adfe096cf4ba89e663b5be90dc7b5c3b259194; twid="u=1954548443927453696"; auth_token=adcae9aa92c2ad370cd5f28346416acc281544b9; __cf_bm=75v93RCvqwo8u1XYc74Qb7txCrAHik8waS8ADN7Qiq0-1761026318.9727426-1.0.1.1-bZnZEiEd74cHlG9k1qd6w7IcmpDpQbknrHIZeCYZJO.AjQZC7eLTlVNvAnXgj9HC_tSOrzTESXeukt.G_4hCTJNj6DHVKbmEfEn42aeb20Dug9ds7bHhm8TahTOPeQPe; personalization_id="v1_8tvuplAF78YI0P0PNzDp4A=="; ct0=131df6e02d28c2651556beda561df3d7420c0b71d8b70508a619a28ff948d3e507aa48b6e8729b757f3a915b296eb3e0cb07b4080e4937436a62f6b4ea06bfcbc4dd60e3f6367248269b2a7a84227f58; __cf_bm=PAnba8yzv5DBr1cxXNwIxDEHgRLvZIuoxdO5hCitq7M-1761026320-1.0.1.1-YII6PST0JA_rEzq_hbUhx5W2uvRaBEReWsYbYNotZSn.SC9UPCxNFUtNuywhetNmjHpQKOVI_sUpfA5_jrVoTzHPgTpmUJ2yGq4LJTegFkA' 这是微软的邮箱的客户端id和刷新troken认证信息,给我写一个使用imap 和 graph api获取邮件的函数
11-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值