[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

send email in asp.net

Posted on 2009-04-07
18
Medium Priority
?
813 Views
Last Modified: 2012-08-13
i want to send email from my web site with using smtp server
my email is ajay@diamondforgood.com
how i send this using c# coding
0
Comment
Question by:chandresh43
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
  • 2
18 Comments
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 24084779
you can try customize this:

using System.Net.Mail;

//..

public static Boolean sendMail(String SenderName, String SenderEmail, String ReceiverName, String ReceiverEmail, String Subject, String Body, Boolean isHTML, String SMTPHost, int SMTPPort, Boolean isAuthenticationNeeded, String SMTPUserName, String SMTPUserPwd)
        {
            try
            {
                SmtpClient sclient = new SmtpClient(SMTPHost, SMTPPort);
                sclient.DeliveryMethod = SmtpDeliveryMethod.Network;
                if (isAuthenticationNeeded)
                {
                    sclient.Credentials = new System.Net.NetworkCredential(SMTPUserName, SMTPUserPwd);                    
                }

                MailMessage mail = new MailMessage();
                mail.Subject = Subject;
                mail.IsBodyHtml = isHTML;
                mail.Body = Body;
                mail.BodyEncoding = System.Text.Encoding.UTF8;
                if (SenderName == "")
                {
                    mail.From = new MailAddress(SenderEmail);
                }
                else
                {
                    mail.From = new MailAddress(SenderEmail, SenderName);
                }
                mail.SubjectEncoding = System.Text.Encoding.UTF8;
                if (ReceiverName == "")
                {
                    mail.To.Add(ReceiverEmail);
                }
                else
                {
                    mail.To.Add(new MailAddress(ReceiverEmail, ReceiverName));
                }
                sclient.Send(mail);
                return true;
            }
            catch (SmtpException)
            {
                return false;
            }
            catch (Exception)
            {
                return false;
            }      
        }



study on System.Net.Mail classes for more info.
http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24084782
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24084783
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Author Comment

by:chandresh43
ID: 24085250
which host i use
my web address is www.diamondforgood.com
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24085271
>>which host i use

basically something like smtp.yourdomain.com or mail.yourdomain.com

You need to check with the Admin or ping the domain to find out..
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24085339
it give error
 Failure sending mail.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24085351
What error message you get here?

Make sure your smtp settings are correct.
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24085354
here is my coding

 protected void Page_Load(object sender, EventArgs e)
    {
        sendMail("ajay", "ajay@diamondforgood.com", "ajay", "ohgod143@yahoo.com", "diamond", "ajay", true, "mail@diamondforgood.com", 8433, true, "ajay", "master");
           

    }


    public static Boolean sendMail(String SenderName, String SenderEmail, String ReceiverName, String ReceiverEmail, String Subject, String Body, Boolean isHTML, String SMTPHost, int SMTPPort, Boolean isAuthenticationNeeded, String SMTPUserName, String SMTPUserPwd)
    {
            SmtpClient sclient = new SmtpClient(SMTPHost, SMTPPort);
            sclient.DeliveryMethod = SmtpDeliveryMethod.Network;
            if (isAuthenticationNeeded)
            {
                sclient.Credentials = new System.Net.NetworkCredential(SMTPUserName, SMTPUserPwd);
            }

            MailMessage mail = new MailMessage();
            mail.Subject = Subject;
            mail.IsBodyHtml = isHTML;
            mail.Body = Body;
            mail.BodyEncoding = System.Text.Encoding.UTF8;
            if (SenderName == "")
            {
                mail.From = new MailAddress(SenderEmail);
            }
            else
            {
                mail.From = new MailAddress(SenderEmail, SenderName);
            }
            mail.SubjectEncoding = System.Text.Encoding.UTF8;
            if (ReceiverName == "")
            {
                mail.To.Add(ReceiverEmail);
            }
            else
            {
                mail.To.Add(new MailAddress(ReceiverEmail, ReceiverName));
            }
            sclient.Send(mail);
            return true;
        }
       

0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24085418
"mail@diamondforgood.com" is invalid, try get the correct SMTP Host and other settings from the site admin...
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24085671
where i found correct mail setting
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24085681
you said to ping then
i ping mail@diamondforgood.com -t
and it give me replay
so i use it
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24086550
I get this:

C:\Documents and Settings\Administrator>ping mail@diamondforgood.com
Ping request could not find host mail@diamondforgood.com. Please check the name
and try again.

please recheck your SMTP settings... ?
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24086875
ping mail.diamondforgood.com -t
and this give me replay
type type in run

0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24087247
So now you still not able to send out emails?

If you not able to, when you debugging your scripts, what's the error message you captured from the exception?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24087260
>>what's the error message you captured from the exception?

I mean the detailed message you get..
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24150034
Bad sequence of commands. The server response was: This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.



thats error i got now
i use host
<system.net>
    <mailSettings>
      <smtp>
        <network host ="mail.diamondforgood.com" userName ="user" password ="pass" defaultCredentials="true"  />        
     
       
      </smtp>
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 24155268
can you post the scripts you using?
0
 
LVL 5

Author Comment

by:chandresh43
ID: 24207002
MailMessage mail = new MailMessage();
        mail.From = new MailAddress(Txtfrom.Text);
        mail.To.Add(Txtto.Text);
        mail.Subject = txtsub.Text;
        mail.Body = txtbody.Text;
        SmtpClient smp = new SmtpClient();


        smp.Send(mail);

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question