Send group email

Source: Internet
Author: User
Tags mailmessage smtpclient

Net2.0 requires service period verification. The Code is as follows:

Needless to say

Public class mail
{
Private string subject;
Private string [] mailto;
Private string body;
Private string smtpserver;
Private string user;
Private string password;
Private string sender;

Public mail (string subject, string [] mailto, string sender, string body, string SMTP, string user, string pass)
{
This. Subject = subject;
This. mailto = mailto;
This. Body = body;
This. smtpserver = SMTP;
This. User = user;
This. Password = pass;
This. Sender = sender;
}
Public bool send ()
{
Bool flag = true;
Try
{
System. net. Mail. mailmessage mailobj = new system. net. Mail. mailmessage ();

// Add mailto address
For (INT I = 0; I <mailto. length; I ++)
{
Mailobj. to. Add (mailto [I]);
}
Mailobj. isbodyhtml = true;
Mailobj. Subject = subject;
String from = user + "@" + smtpserver. substring (smtpserver. indexof (".") + 1, smtpserver. Length-smtpserver. indexof (".")-1 );
Mailobj. From = new mailaddress (from, sender, system. Text. encoding. utf8 );
Mailobj. Body = body;
System. net. Mail. smtpclient smtpmail = new smtpclient (smtpserver );
Smtpmail. Credentials = new system. net. networkcredential (from, password );
Smtpmail. Send (mailobj );
Flag = true;
}
Catch
{
Flag = false;
}
Return flag;
}
}

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/mengyao/archive/2007/08/29/1764256.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.