Sunteți pe pagina 1din 5

MailHelper.

cs
using System.Net.Mail;
public class MailHelper
{
/// <summary>
/// Sends an mail message
/// </summary>
/// <param name="from">Sender address</param>
/// <param name="to">ecepient address</param>
/// <param name="bcc">!cc recepient</param>
/// <param name="cc">"c recepient</param>
/// <param name="sub#ect">Sub#ect of mail message</param>
/// <param name="body">!ody of mail message</param>
public
static $oid SendMailMessage%string from& string to& string bcc& string cc& string sub#ect&string body'
{
// (nstantiate a ne) instance of MailMessage
MailMessage mMailMessage = ne) MailMessage%';
// Set t*e sender address of t*e mail message
mMailMessage.+rom = ne) Mail,ddress%from';
// Set t*e recepient address of t*e mail message
mMailMessage.-o.,dd%ne) Mail,ddress%to'';
// "*ec. if t*e bcc $alue is null or an empty string
if %%bcc /= null' 00 %bcc /= string.1mpty''
{
// Set t*e !cc address of t*e mail message
mMailMessage.!cc.,dd%ne) Mail,ddress%bcc'';
2
// "*ec. if t*e cc $alue is null or an empty $alue
if %%cc /= null' 00 %cc /= string.1mpty''
{
// Set t*e "" address of t*e mail message
mMailMessage."".,dd%ne) Mail,ddress%cc'';
2 // Set t*e sub#ect of t*e mail message
mMailMessage.Sub#ect = sub#ect;
// Set t*e body of t*e mail message
mMailMessage.!ody = body;
// Set t*e format of t*e mail message body as H-M3
mMailMessage.(s!odyHtml = true;
// Set t*e priority of t*e mail message to normal
mMailMessage.4riority = Mail4riority.Normal;
// (nstantiate a ne) instance of Smtp"lient
Smtp"lient mSmtp"lient = ne) Smtp"lient%';
// Send t*e mail message
mSmtp"lient.Send%mMailMessage';
2
2
//Write in Web.config
<56ml $ersion="7.8"5>
<configuration>
<system.net>
<mailSettings>
<smtp from="default1mail9yourdomain.com">
<net)or. *ost="smtp.yourdomain.com" port=":;" userName="your<serName"pass)ord="your4ass)ord"/>
</smtp>
</mailSettings>
</system.net>
</configuration>
Send via gmail
private void send_form()
{
try
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(FROM email id ere!" #O email id ere"
$o%r S%&'e(t )ere!"!$o%r #*+# ere!),
--.roper /%tenti(ation 0etails need to &e passed wen sending email from gmail System.Net.Networ12redential
mail/%tenti(ation = new System.Net.Networ12redential(yo%r email-login id ere!" password ere!),
--Smtp Mail server of 3mail is smpt.gmail.(om! and its port no. 456 System.Net.Mail.Smtp2lient mail2lient = new
System.Net.Mail.Smtp2lient(smtp.gmail.(om!" 456),
--*na&le SS7
--3mail is SS7 (ertify so tat wy we need to set *na&elssl=tr%e
mail2lient.*na&leSsl = tr%e,
mail2lient.8se0efa%lt2redentials = false,
mail2lient.2redentials = mail/%tenti(ation,
mail.9s:ody)tml = tr%e,
-- 9t will send te email
mail2lient.Send(mail),
Response.;rite(*mail Sent!),
<
(at((*=(eption e=)
{
Response.;rite( e=.Message.#oString()),
<
<
Net 1.1
<=9 4age language="">" =>
<=9 (M4?- namespace="System.@eb.Mail" =>
<=
MailMessage oMessage = ne) MailMessage%';
oMessage.-o = "user9domain.com";
oMessage.+rom = "you9domain.com";
oMessage.Sub#ect = "-est message sent using System.@eb.Mail";
oMessage.!ody = "-*is is a test message.";

oMessage.+ieldsA"*ttpB//sc*emas.microsoft.com/cdo/configuration/sendusin
g"C = :;

oMessage.+ieldsA"*ttpB//sc*emas.microsoft.com/cdo/configuration/smtpser$
er"C = "mymail.brin.ster.com";

oMessage.+ieldsA"*ttpB//sc*emas.microsoft.com/cdo/configuration/senduser
name"C = "you9domain.com";

oMessage.+ieldsA"*ttpB//sc*emas.microsoft.com/cdo/configuration/sendpass
)ord"C = "pass)ord";

oMessage.+ieldsA"*ttpB//sc*emas.microsoft.com/cdo/configuration/smtpaut*
enticate"C = 7;
System.@eb.Mail.SmtpMail.SmtpSer$er = "mail.DourEomain.com";

try
{
System.@eb.Mail.SmtpMail.Send%oMessage';
esponse.@rite%"1mail sent/"';
2
catc* %16ception 16'
{
esponse.@rite%"<nable to send mail/ " F 16.Message';
2
=>
Bill Gates
A">C
using System;
using System.@eb.Mail;

namespace SendMail
{
class usage
{
public $oid Eisplay<sage%'
{
"onsole.@rite3ine%"<sage SendMail.e6e <to> <from> <sub#ect>
<body>"';
"onsole.@rite3ine%"<to> t*e addresses of t*e email
recipients"';
"onsole.@rite3ine%"<from> your email address"';
"onsole.@rite3ine%"<sub#ect> sub#ect of your email"';
"onsole.@rite3ine%"<body> t*e te6t of t*e email"';
"onsole.@rite3ine%"16ampleB"';
"onsole.@rite3ine%"SendMail.e6e
Some?ne9"ontoso.com;Some?t*er9"ontoso.com Me9contoso.com Hi *ello"';
2
2

class Start
{
// -*e main entry point for t*e application.
AS-,-*readC
static $oid Main%stringAC args'
{
try
{
try
{
MailMessage Message = ne) MailMessage%';
Message.-o = argsA8C;
Message.+rom = argsA7C;
Message.Sub#ect = argsA:C;
Message.!ody = argsAGC;
try
{
SmtpMail.SmtpSer$er = "your mail ser$er name goes
*ere";
SmtpMail.Send%Message';
2
catc*%System.@eb.Http16ception e*ttp'
{
"onsole.@rite3ine%"{82"& e*ttp.Message';
"onsole.@rite3ine%"Here is t*e full error message
output"';
"onsole.@rite%"{82"& e*ttp.-oString%'';
2
2
catc*%(nde6?ut?fange16ception'
{
usage use = ne) usage%';
use.Eisplay<sage%';
2
2
catc*%System.16ception e'
{
"onsole.@rite3ine%"<n.no)n 16ception occurred {82"&
e.Message';
"onsole.@rite3ine%"Here is t*e +ull Message output"';
"onsole.@rite3ine%"{82"& e.-oString%'';
2
2
2
2
using System;
using System.@eb.Mail;
namespace @ebMail
{
class "lass7
{
static $oid Main%stringAC args'
{
try
{
MailMessage oMsg = ne) MailMessage%';
// -?E?B eplace )it* sender eHmail address.
oMsg.+rom = "sender9some)*ere.com";
// -?E?B eplace )it* recipient eHmail address.
oMsg.-o = "recipient9some)*ere.com";
oMsg.Sub#ect = "Send <sing @eb Mail";

// S1NE (N H-M3 +?M,- %comment t*is line to send plain te6t'.
oMsg.!ody+ormat = Mail+ormat.Html;

// H-M3 !ody %remo$e H-M3 tags for plain te6t'.
oMsg.!ody = "<H-M3><!?ED><!>Hello @orld/</!></!?ED></H-M3>";

// ,EE ,N ,--,"HM1N-.
// -?E?B eplace )it* pat* to attac*ment.
String s+ile = 9""BItempIHello.t6t";
Mail,ttac*ment o,ttc* = ne) Mail,ttac*ment%s+ile& Mail1ncoding.!aseJK';

oMsg.,ttac*ments.,dd%o,ttc*';
// -?E?B eplace )it* t*e name of your remote SM-4 ser$er.
SmtpMail.SmtpSer$er = "MySM-4Ser$er";
SmtpMail.Send%oMsg';
oMsg = null;
o,ttc* = null;
2
catc* %16ception e'
{
"onsole.@rite3ine%"{82 16ception caug*t."& e';
2
2
2
2
ompound interest arises when interest is added to the principal so that from that moment on, the interest that has been added also itself earns interest. This
addition of interest to the principal is called compounding.
The following formula gives you the total amount one will get if compounding is done:-


Where,
A = Final Amount that will be received
= rincipal Amount !i.e. initial investment"
r = Annual nominal interest rate !as a decimal i.e. if interest is paid at #.#$ pa, then it will be %.%##" !it should not be in percentage"
n = number of times the interest is compounded per year !i.e. for monthly compounding n will be &', for half year compounding it will be ' and for
(uarter it will be )
t = number of years
*To arrive at the interest amount you can further use the formula +nterest = A - ,
-.ample: /et us assume that an amount of 0s.&#%%.%% is deposited in a ban1 for 2 years and paying an annual interest rate of ).3$, compounded (uarterly.
A. Thus, the above formula values will be = &#%%, r = ).34&%% = %.%)3, n = ), and t = 2:
5o, the balance after 2 years is 0s.&,637.7) !or rounded to 0s.&636".
*To arrive at the interest amount = A - = &637.7) - &#%% = 0s. )37.7) ,

S-ar putea să vă placă și