
{"id":218,"date":"2008-03-10T20:56:00","date_gmt":"2008-03-10T20:56:00","guid":{"rendered":"http:\/\/www.sincebirth.cn\/?p=218"},"modified":"2008-03-10T20:56:00","modified_gmt":"2008-03-10T20:56:00","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8gmail%e5%8f%91%e9%80%81%e9%82%ae%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/niuduer.sincebirth.space\/?p=218","title":{"rendered":"\u5982\u4f55\u4f7f\u7528gmail\u53d1\u9001\u90ae\u4ef6"},"content":{"rendered":"<div id=\"blog_text\" class=\"cnt\">\n<p><span style=\"color: #000000\">using System.Web.Mail;<\/p>\n<p>\n&nbsp;&nbsp;&nbsp;  \/\/ Mail initialization<br \/>\nMailMessage mailMsg = new MailMessage();<br \/>\nmailMsg.From = &quot;test@test.com&quot;;<br \/>\nmailMsg.To = &quot;desti@126.com&quot;;<br \/>\n\/\/mailMsg.Cc = cc;<br \/>\n\/\/mailMsg.Bcc = bcc;<br \/>\nmailMsg.Subject = &quot;send mail use gmail&quot;;<br \/>\nmailMsg.BodyFormat = MailFormat.Text;<br \/>\nmailMsg.Body = &quot;Hello here comes the sun&quot;;<br \/>\nmailMsg.Priority = MailPriority.High;<br \/>\n\/\/ Smtp configuration<br \/>\nSmtpMail.SmtpServer = &quot;smtp.gmail.com&quot;;<br \/>\n\/\/ &#8211; smtp.gmail.com use smtp authentication<br \/>\nmailMsg.Fields.Add(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpauthenticate&quot;, &quot;1&quot;);<br \/>\nmailMsg.Fields.Add(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendusername&quot;, &quot;yourgmailaddress&quot;);<br \/>\nmailMsg.Fields.Add(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/sendpassword&quot;, &quot;youpassword&quot;);<br \/>\n\/\/ &#8211; smtp.gmail.com use port 465 or 587<br \/>\nmailMsg.Fields.Add(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpserverport&quot;, &quot;465&quot;);<br \/>\n\/\/ &#8211; smtp.gmail.com use STARTTLS (some call this SSL)<br \/>\nmailMsg.Fields.Add(&quot;http:\/\/schemas.microsoft.com\/cdo\/configuration\/smtpusessl&quot;, &quot;true&quot;);<br \/>\n\/\/ try to send Mail<br \/>\ntry<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;  SmtpMail.Send(mailMsg);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;  Response.Write(&quot;send success&quot;);<br \/>\n}<br \/>\ncatch (Exception ex)<br \/>\n{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;  Response.Write(ex.Message);<br \/>\n}<\/span><\/p>\n<p><span style=\"color: #000000\">\u8f6c\u81ea\uff1a<a href=\"http:\/\/www.cnblogs.com\/sunbingzibo\/archive\/2008\/03\/07\/1094831.html\">http:\/\/www.cnblogs.com\/sunbingzibo\/archive\/2008\/03\/07\/1094831.html<\/a><\/span><\/p>\n<p><span style=\"color: #000000\">\u627edotnet\u7684\u8d44\u6599\u8fd8\u662f\u4e0acsdn\u548ccnblogs\uff0c\u5728\u8fd9\u91cc\u770b\u5230\u7b97\u4f60\u5e78\u8fd0\uff0c\u653e\u5fc3\u5427\uff0c2008\u5e743\u670810\u65e520\u70b954\u5206\u53d1\u9001\u5230126\u90ae\u7bb1\u6210\u529f\u3002<\/span><\/p>\n<p><span style=\"color: #000000\">\u6ce8\u610f\uff1aG\u5b98\u65b9\u9650\u5236\u4e00\u5929\u5185\u540c\u4e00\u5c01\u90ae\u4ef6\u6700\u591a\u53d1\u9001\u5230500\u4e2a\u8054\u7cfb\u4eba\u3002<\/span><\/p>\n<p><span style=\"color: #000000\">\u4ee5\u4e0a\u4ee3\u7801\u7b26\u5408.net1.1\u89c4\u8303\uff0c2.0\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<p><span style=\"color: #000000\"><\/p>\n<div style=\"border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee\"><img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><span style=\"color: #0000ff\">using<\/span><span style=\"color: #000000\"> System;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">using<\/span><span style=\"color: #000000\"> System.Collections.Generic;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">using<\/span><span style=\"color: #000000\"> System.Text;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">using<\/span><span style=\"color: #000000\"> System.Net.Mail;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">using<\/span><span style=\"color: #000000\"> System.Net; <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">namespace<\/span><span style=\"color: #000000\"> Artech.Mail.ConsoleApp<br \/>\n<img decoding=\"async\" align=\"top\" codehighlighter1_142_1183_closed_text.style.display=\"'inline';\" codehighlighter1_142_1183_closed_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315297.gif\"><img decoding=\"async\" style=\"display: none\" align=\"top\" codehighlighter1_142_1183_open_text.style.display=\"'inline';\" codehighlighter1_142_1183_open_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315298.gif\"><\/span><span style=\"border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff\"><img decoding=\"async\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315299.gif\"><\/span><span><span style=\"color: #000000\">{ <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">class<\/span><span style=\"color: #000000\"> Program<br \/>\n<img decoding=\"async\" align=\"top\" codehighlighter1_166_1181_closed_text.style.display=\"'inline';\" codehighlighter1_166_1181_closed_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152911.gif\"><img decoding=\"async\" style=\"display: none\" align=\"top\" codehighlighter1_166_1181_open_text.style.display=\"'inline';\" codehighlighter1_166_1181_open_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152912.gif\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff\"><img decoding=\"async\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315299.gif\"><\/span><span><span style=\"color: #000000\">{<\/p>\n<div class=\"Mqc212\"> <\/div>\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> ADDRESS_FROM <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">from@gail.com<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> ADDRESS_TO <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">to@gmail.com<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">; <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> USER_ID <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">MyAccount<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> PASSWORD <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">password<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">; <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> SMTP_SERVER <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">smtp.gmail.com<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">const<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">int<\/span><span style=\"color: #000000\"> PORT <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #000000\">587<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\"> <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">void<\/span><span style=\"color: #000000\"> Main(<\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\">[] args)<br \/>\n<img decoding=\"async\" align=\"top\" codehighlighter1_491_598_closed_text.style.display=\"'inline';\" codehighlighter1_491_598_closed_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152911.gif\"><img decoding=\"async\" style=\"display: none\" align=\"top\" codehighlighter1_491_598_open_text.style.display=\"'inline';\" codehighlighter1_491_598_open_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152912.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff\"><img decoding=\"async\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315299.gif\"><\/span><span><span style=\"color: #000000\">{<\/p>\n<p class=\"Mqc212\">\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  SendMail(SMTP_SERVER, PORT);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.Read();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152928.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<\/span><\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">void<\/span><span style=\"color: #000000\"> SendMail(<\/span><span style=\"color: #0000ff\">string<\/span><span style=\"color: #000000\"> smtpServer, <\/span><span style=\"color: #0000ff\">int<\/span><span style=\"color: #000000\"> port)<\/p>\n<p class=\"Mqc212\">\n<p>\n<img decoding=\"async\" align=\"top\" codehighlighter1_667_1175_closed_text.style.display=\"'inline';\" codehighlighter1_667_1175_closed_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152911.gif\"><img decoding=\"async\" style=\"display: none\" align=\"top\" codehighlighter1_667_1175_open_text.style.display=\"'inline';\" codehighlighter1_667_1175_open_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152912.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff\"><img decoding=\"async\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315299.gif\"><\/span><span><span style=\"color: #000000\">{ <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  SmtpClient mailClient <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">new<\/span><span style=\"color: #000000\"> SmtpClient(smtpServer, <\/span><span style=\"color: #000000\">587<\/span><span style=\"color: #000000\">);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  mailClient.EnableSsl <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">true<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  NetworkCredential crendetial <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">new<\/span><span style=\"color: #000000\"> NetworkCredential(USER_ID, PASSWORD);<\/p>\n<div class=\"Mqc212\"> <\/div>\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  mailClient.Credentials <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> crendetial;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  MailMessage message <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">new<\/span><span style=\"color: #000000\"> MailMessage(ADDRESS_FROM, ADDRESS_TO, <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">This is a subject<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">This is the body of the mail<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">); <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  mailClient.Send(message);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">Mail has been sent to &#8216;{0}&#8217;<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">, ADDRESS_TO);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152928.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<\/span><\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152928.gif\">&nbsp;&nbsp;&nbsp;&nbsp;  }<\/span><\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152944.gif\">}<\/span><\/span><span style=\"color: #000000\"><\/p>\n<div class=\"Mqc212\"> <\/div>\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><\/div>\n<p style=\"font-size: 10pt\">\u719f\u6089System.Net.Mail. SmtpClient\uff0c\u5bf9\u4e0a\u9762\u7684Code\u5e94\u8be5\u662f\u5f88\u719f\u6089\u4e86\uff0c\u5728\u8fd9\u91cc\u6211\u5c31\u4e0d\u60f3\u5bf9\u4e0a\u9762\u7684\u903b\u8f91\u591a\u505a\u4ecb\u7ecd\u4e86\u3002\u4e0d\u8fc7\u6211\u9700\u8981\u8865\u5145\u51e0\u70b9\u7684\u662f\uff1a<\/p>\n<p class=\"Mqc212\">\n<\/p>\n<p style=\"font-size: 10pt\">1\uff0e\u901a\u8fc7Gmail\uff0c\u4f60\u53ea\u80fd\u4ee5\u4f60\u767b\u5f55\u5230SMTP Server\u7684Account\u7684\u540d\u4e49\u5bf9\u5916\u53d1\u4fe1\uff0c\u4ee5\u4e0a\u9762\u4e3a\u4f8b\uff0c\u6211\u4ee5&rdquo; MyAccount&rdquo;\u6700\u4e3aGmail\u7684Account\u767b\u5f55\uff0c\u5411Email address \u4e3a<a style=\"otarget: _blank\" target=\"_blank\" href=\"mailto:to@gmail.com\">to@gmail.com<\/a>\u53d1\u9001\u90ae\u4ef6\uff0c\u867d\u7136\u5728SmtpClient.Send\u65b9\u6cd5\u4e2d\u7684\u6211\u6307\u5b9a\u7684From address\u4e3a<a style=\"otarget: _blank\" target=\"_blank\" href=\"mailto:from@gail.com\">from@gail.com<\/a>\uff0c\u5f53\u6536\u4fe1\u4eba\u53d7\u5230\u8be5\u90ae\u4ef6\u7684\u65f6\u5019\uff0c\u90ae\u4ef6\u7684\u53d1\u4ef6\u4eba\u662f<a style=\"otarget: _blank\" target=\"_blank\" href=\"mailto:MyAccount@gail.com\">MyAccount@gail.com<\/a>\uff0c\u4e0d\u4f1a\u4e3a<a style=\"otarget: _blank\" target=\"_blank\" href=\"mailto:from@gail.com\">from@gail.com<\/a>\u3002\u8fd9\u4e9b\u5f88\u6709\u5fc5\u8981\u7684\uff0c\u53ef\u4ee5\u9632\u6b62\u4f60\u5229\u7528\u522b\u4eba\u7684\u540d\u4e49\u53d1\u9001\u90ae\u4ef6\u3002\u8fd9\u79cd\u673a\u5236\u5e76\u4e0d\u662f\u901a\u7528\u7684\uff0c\u6211\u5c31\u548c\u540c\u4e8b\u5f00\u8fc7\u8fd9\u6837\u7684\u73a9\u7b11\uff1a\u901a\u8fc7\u516c\u53f8\u7684STMP Server\u4ee5\u53e6\u4e00\u4e2a\u540c\u4e8b\u7684\u540d\u4e49\u5411\u4ed6\u53d1\u90ae\u4ef6\u3002<\/p>\n<p style=\"font-size: 10pt\">2\uff0e\u867d\u7136Google\u5bf9\u5916\u5ba3\u79f0\u4ed6\u4eec\u5f00\u53d1\u7684SMTP Server\u7684Port\u4e3a25\uff0c465\u548c587\uff0c\u4f46\u662f\u5728\u4ee3\u7801\u4e2d\uff0c\u6211\u4f7f\u752825\u548c587\u4e00\u5207\u6b63\u5e38\uff0c\u5f53\u65f6\u5f53\u6211\u4f7f\u7528465\u7684\u65f6\u5019\uff0c\u600e\u4e48\u4e5f\u53d1\u4e0d\u51fa\u53bb\u3002\u4f46\u662f\u5f53\u6211\u5728Outlook\u4e2d\u628aPort\u914d\u7f6e\u4e3a465\u7684\u65f6\u5019\uff0c\u53d1\u9001\u90ae\u4ef6\u4e5f\u6b63\u5e38\u3002\u6211\u8fd8\u6ca1\u6765\u5f97\u53ca\u67e5\u9605\u5230\u5e95\u662f\u4ec0\u4e48\u95ee\u9898\u3002\u77e5\u9053\u539f\u56e0\u7684\u670b\u53cb\uff0c\u8bf7\u4e0d\u541d\u8d50\u6559\u3002<\/p>\n<p class=\"Mqc212\">\n<\/p>\n<p style=\"font-size: 10pt\">3\uff0e\u5bf9\u4e8e\u50cf\u8fd9\u79cd\u90ae\u4ef6\u670d\u52a1\u529f\u80fd\u7684\u4ee3\u7801\uff0c\u6211\u4eec\u4e00\u822c\u5199\u6210\u53ef\u914d\u7f6e\u7684\u3002\u56e0\u4e3a\u5bf9\u4e8e\u5bf9\u4e8e\u5e10\u6237\u548c\u5bc6\u7801\uff0c\u751a\u81f3\u662fSTMP Server\uff0c\u90fd\u6709\u53ef\u80fd\u7ecf\u5e38\u7684\u53d8\u6362\u3002\u4f46\u662f\u6211\u4eec\u4e0d\u7528\u901a\u8fc7\u5e38\u7528\u7684&lt;AppSettings&gt;\u6765\u914d\u7f6e\uff0c\u4e5f\u4e0d\u7528\u5b9a\u4e49\u6211\u4eec\u7684Custom ConfigurationSection\u3002\u56e0\u4e3aConfiguration System\u5df2\u7ecf\u4e3a\u6211\u4eec\u5b9a\u4e49\u7684\u5185\u7f6e\u7684&lt;mailSettings&gt;\u6765\u914d\u7f6e\u90ae\u4ef6\u76f8\u5173\u7684\u4fe1\u606f\u3002\u6bd4\u5982\uff1a<\/p>\n<div style=\"border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee\"><img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><span style=\"color: #0000ff\">&lt;?<\/span><span style=\"color: #ff00ff\">xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; <\/span><span style=\"color: #0000ff\">?&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">configuration<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">system<\/span><span style=\"color: #ff0000\">.net<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"> <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">mailSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">smtp <\/span><span style=\"color: #ff0000\">from<\/span><span style=\"color: #0000ff\">=&quot;MyAccount@gmail.com&quot;<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;<\/span><span style=\"color: #800000\">network <\/span><span style=\"color: #ff0000\">host<\/span><span style=\"color: #0000ff\">=&quot;smtp.gmail.com&quot;<\/span><span style=\"color: #ff0000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  password<\/span><span style=\"color: #0000ff\">=&quot;password&quot;<\/span><span style=\"color: #ff0000\"> <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  port<\/span><span style=\"color: #0000ff\">=&quot;587&quot;<\/span><span style=\"color: #ff0000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  userName<\/span><span style=\"color: #0000ff\">=&quot; MyAccount @gmail.com&quot;<\/span><span style=\"color: #0000ff\">\/&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">smtp<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">mailSettings<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"> <br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\">&nbsp;&nbsp;<\/span><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">system.net<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><span style=\"color: #0000ff\">&lt;\/<\/span><span style=\"color: #800000\">configuration<\/span><span style=\"color: #0000ff\">&gt;<\/span><span style=\"color: #000000\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><\/span><\/div>\n<p style=\"font-size: 10pt\">\u5bf9\u4e8eGmail\uff0cfrom\u5b9e\u9645\u4e0a\u6ca1\u6709\u4ec0\u4e48\u610f\u4e49\u3002<\/p>\n<p style=\"font-size: 10pt\">\u73b0\u5728\u6211\u4eec\u5c31\u53ef\u4ee5\u8fdb\u4e00\u6b65\u5730\u7b80\u5316\u6211\u4eec\u7684Managed code\u4e86\uff1a<\/p>\n<div class=\"Mqc212\"> <\/div>\n<\/p>\n<p style=\"font-size: 10pt\">\n<p class=\"Mqc212\">\n<\/p>\n<p style=\"font-size: 10pt\">\n<p class=\"Mqc212\">\n<\/p>\n<div style=\"border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee\"><img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315290.gif\"><span style=\"color: #0000ff\">static<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">void<\/span><span style=\"color: #000000\"> SendMail()<br \/>\n<img decoding=\"async\" align=\"top\" codehighlighter1_31_379_closed_text.style.display=\"'inline';\" codehighlighter1_31_379_closed_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315297.gif\"><img decoding=\"async\" style=\"display: none\" align=\"top\" codehighlighter1_31_379_open_text.style.display=\"'inline';\" codehighlighter1_31_379_open_image.style.display=\"'inline';\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315298.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"border-right: #808080 1px solid; border-top: #808080 1px solid; display: none; border-left: #808080 1px solid; border-bottom: #808080 1px solid; background-color: #ffffff\"><img decoding=\"async\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/1315299.gif\"><\/span><span><span style=\"color: #000000\">{<\/p>\n<div class=\"Mqc212\"> <\/div>\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  SmtpClient mailClient <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">new<\/span><span style=\"color: #000000\"> SmtpClient();<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  mailClient.EnableSsl <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">true<\/span><span style=\"color: #000000\">;<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  MailMessage message <\/span><span style=\"color: #000000\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #0000ff\">new<\/span><span style=\"color: #000000\"> MailMessage(ADDRESS_FROM, ADDRESS_TO, <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">This is a subject<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">This is the body of the mail<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">);<\/p>\n<p class=\"Mqc212\">\n<p>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\"><br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  mailClient.Send(message);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152910.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">Mail has been sent to &#8216;{0}&#8217;<\/span><span style=\"color: #000000\">&quot;<\/span><span style=\"color: #000000\">, ADDRESS_TO);<br \/>\n<img decoding=\"async\" align=\"top\" src=\"http:\/\/www.admin5.com\/upimg\/allimg\/070516\/13152944.gif\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  }<\/span><\/span><span style=\"color: #000000\"><br \/>\n<\/span><\/div>\n<p><\/span><\/p>\n<p><span style=\"color: #000000\">\uff08<a href=\"http:\/\/www.2ey.cn\/showart.asp?art_id=338\">http:\/\/www.2ey.cn\/showart.asp?art_id=338<\/a>\uff09<\/span><\/p>\n<p><span style=\"color: #000000\">\u53ef\u89c1\u7aef\u53e3\u8bbe\u5b9a\u53d8\u4e3a\u6700\u91cd\u8981\u7684\u4e00\u9879\uff0c\u770b\u51c6\u4e86\u75282.0\u65f6\u4e0d\u80fd\u7528465\u7aef\u53e3\uff0c\u800c\u8981\u7528587\uff0c\u6628\u665a\u4e0a\u53d1\u540e\u4e00\u534a\u7528\u4e86\u534a\u4e2a\u5c0f\u65f6\u4e5f\u4e0d\u6210\u529f\u3002<\/span><\/p>\n<p><span style=\"color: #000000\">\u53ef\u662f\u7528passwordrecovery\u63a7\u4ef6\u7684\u65f6\u5019\u51fa\u4e86\u95ee\u9898\uff0c\u5b83\u9ed8\u8ba4\u7684enablessl\u662ffalse,\u6211\u53c8\u61d2\u5f97\u81ea\u5df1\u5199\u4e00\u4e2a\u51fa\u6765\uff0c\u6240\u4ee5\u5728\u8be5\u7a7a\u95f4\u7684sendingmail\u4e8b\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff08\u4e0d\u8981\u5fd8\u4e86using System.Net.Mail;\uff09\uff1a<\/span><\/p>\n<p><span style=\"color: #000000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  MailMessage mail = e.Message;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  e.Cancel = true;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  SmtpClient smtp = new SmtpClient();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  smtp.EnableSsl = true;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  smtp.Send(mail);<\/span><\/p>\n<p><span style=\"color: #000000\">\u8fd9\u6837\u5c31\u641e\u5b9a\u4e86\u3002<\/span><\/p>\n<p><span style=\"color: #000000\">\u7136\u540e\u6211\u518d\u67e5\u67e5\u600e\u4e48\u4e30\u5bcc\u4e00\u4e0b\u90ae\u4ef6\u5185\u5bb9\uff0c\u5373\u8bbe\u7f6e(Mail)BodyFile<\/span><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>using System.Web.Mail; &nbsp;&nbsp;&nbsp; \/\/ Mail initi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-218","post","type-post","status-publish","format-standard","hentry","category-all"],"views":1630,"_links":{"self":[{"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=\/wp\/v2\/posts\/218","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=218"}],"version-history":[{"count":0,"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=\/wp\/v2\/posts\/218\/revisions"}],"wp:attachment":[{"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/niuduer.sincebirth.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}