text stringlengths 0 13.4k |
|---|
<httpHandlers> |
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> |
</httpHandlers> |
</system.web> |
<!-- IIS 7 --> |
<system.webServer> |
<handlers> |
<remove name="BlockViewHandler"/> |
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" |
type="System.Web.HttpNotFoundHandler"/> |
</handlers> |
</system.webServer> |
GoalKicker.com – .NET Framework Notes for Professionals |
102 |
Chapter 30: System.Net.Mail |
Section 30.1: MailMessage |
Here is the example of creating of mail message with attachments. After creating we send this message with the |
help of SmtpClient class. Default 25 port is used here. |
public class clsMail |
{ |
private static bool SendMail(string mailfrom, List<string>replytos, List<string> mailtos, |
List<string> mailccs, List<string> mailbccs, string body, string subject, List<string> Attachment) |
{ |
try |
{ |
using(MailMessage MyMail = new MailMessage()) |
{ |
MyMail.From = new MailAddress(mailfrom); |
foreach (string mailto in mailtos) |
MyMail.To.Add(mailto); |
if (replytos != null && replytos.Any()) |
{ |
foreach (string replyto in replytos) |
MyMail.ReplyToList.Add(replyto); |
} |
if (mailccs != null && mailccs.Any()) |
{ |
foreach (string mailcc in mailccs) |
MyMail.CC.Add(mailcc); |
} |
if (mailbccs != null && mailbccs.Any()) |
{ |
foreach (string mailbcc in mailbccs) |
MyMail.Bcc.Add(mailbcc); |
} |
MyMail.Subject = subject; |
MyMail.IsBodyHtml = true; |
MyMail.Body = body; |
MyMail.Priority = MailPriority.Normal; |
if (Attachment != null && Attachment.Any()) |
{ |
System.Net.Mail.Attachment attachment; |
foreach (var item in Attachment) |
{ |
attachment = new System.Net.Mail.Attachment(item); |
MyMail.Attachments.Add(attachment); |
} |
} |
SmtpClient smtpMailObj = new SmtpClient(); |
smtpMailObj.Host = "your host"; |
smtpMailObj.Port = 25; |
smtpMailObj.Credentials = new System.Net.NetworkCredential("uid", "pwd"); |
smtpMailObj.Send(MyMail); |
return true; |
GoalKicker.com – .NET Framework Notes for Professionals |
103 |
} |
} |
catch |
{ |
return false; |
} |
} |
} |
Section 30.2: Mail with Attachment |
MailMessage represents mail message which can be sent further using SmtpClient class. Several attachments (files) |
can be added to mail message. |
using System.Net.Mail; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.