Using. Net to implement the Code that automatically sends emails in the background, you can save some basic information in the web. config file:
Web. config file information segment:
Code <system.net> <mailsettings> <SMTP deliverymethod = "network" from = "yanggl@hotmail.com"> <network host = "smtp.hotmail.com" username = "yanggl@hotmail.com" Password = "" defaultcredentials = "true "/> </SMTP> </mailsettings> </system.net>
Background implementation:
Code using system. net. mail; using system. configuration; using system. net. configuration; using system. web. configuration; // addresses for send email. string [] address = new string [] {"guilin_gavin@hotmail.com", "glyang@isoftstone.com"}; // email body. string emailbody = "Hello! Guys! "; // Email subject. String subject =" this is a test! "; // Get the config info. smtpsection = netsectiongroup. getsectiongroup (webconfigurationmanager. openwebconfiguration ("~ /Web. config ")). mailsettings. SMTP; // Save the mail object. mailmessage Mm = new mailmessage (); foreach (string item in address) mm. to. add (item); mm. from = new mailaddress (smtpsection. from); mm. bodyencoding = system. text. encoding. utf8; mm. subjectencoding = system. text. encoding. utf8; mm. isbodyhtml = true; mm. body = emailbody; mm. subject = subject; // set and send email. smtpclient SC = new smtpclient (smtpsection. network. host); SC. deliverymethod = smtpdeliverymethod. network; SC. credentials = new system. net. networkcredential (smtpsection. network. username, smtpsection. network. password); SC. send (mm );