Use. Net to automatically send emails in the backgroundCodeYou can save some basic information in the web. config file:
Web. config file information segment:
Code < System.net >
< Mailsettings >
< SMTP deliverymethod = " Network " From = " Email address to be sent " >
< Network host = " SMTP address of the email to be sent " Username = " Email address to be sent " Password = " Email Password " Defaultcredentials = " True " />
</ SMTP >
</ Mailsettings >
</ System.net >
Background implementation:
Code UsingSystem. net. mail;
UsingSystem. configuration;
UsingSystem. net. configuration;
UsingSystem. Web. configuration;
// Addresses for send email.
String [] Address = New String [] { " Recipient address 1 " , " Recipient address 2 " };
// 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 );