Sending Email

Status
Not open for further replies.

persiantnt

New Member
Messages
2
Reaction score
0
Points
0
Sending Email - ASP.NET 2



public static bool SendEmail( string from,string displayName,string subject, string[] to, string body )
{
try
{
System.Net.Mail.
MailMessage mail = new System.Net.Mail.MailMessage();
mail.Body = body;
mail.IsBodyHtml =
true;
mail.From =
new System.Net.Mail.MailAddress(from, displayName, Encoding.UTF8);
mail.Sender =
new System.Net.Mail.MailAddress(from, displayName, Encoding.UTF8);
mail.Subject = subject;
mail.SubjectEncoding =
Encoding.UTF8;
mail.Priority = System.Net.Mail.
MailPriority.High;
foreach( string s in to ) mail.To.Add( s );
System.Net.Mail.
SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host =
"mail.server.com";
smtp.Credentials =
new System.Net.NetworkCredential("info@server.com","password");
smtp.Send( mail );
}
catch(...)
{
return false;
}
return true;

}









ASP.NET Send Mail

System.Web.Mail.MailMessage msg =


}

public static bool SendMail( string From, string To, string Subject, string body, string[] attachments )
{
try
{new System.Web.Mail.MailMessage( );
msg.From = From;
msg.To = To;
msg.Subject =Subject;
msg.BodyFormat = System.Web.Mail.MailFormat.Html;
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.Body = body;
msg.Priority = System.Web.Mail.MailPriority.High;
if( attachments != null )
{
foreach( string s in attachments )
{
msg.Attachments.Add(
new System.Web.Mail.MailAttachment( s ));
}
}
string AccountName = "your email address";
string AccountPassword = "your email password";
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", 1 );
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername" , AccountName );
msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword" , AccountPassword ); System.Web.Mail.SmtpMail.SmtpServer = "your mail server address";
System.Web.Mail.SmtpMail.Send( msg );
catch( Exception )
{
return false;
}
return true;
}

 
Status
Not open for further replies.
Top