Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need my ASP.NET MVC site to send an email

Posted on 2011-03-02
7
Medium Priority
?
333 Views
Last Modified: 2012-05-11
Instead of needing a listener, I could insert a line of code in one function to notify my BlackBerry anytime my program throws an exception. So please provide me the code (or link to the code) so I can have my C# program send an outbound email.

Thanks,
newbieweb
0
Comment
Question by:newbieweb
[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
  • 4
  • 3
7 Comments
 

Author Comment

by:newbieweb
ID: 35021277
I configured the attached code but the email is not going out. Is doesn not throw an exception but I never get an email.

for txtFrom I am using my working email address.  Is that right or should it be a mail server??
private void SendEmail(MailAddressCollection txtTo, MailAddress txtFrom, string txtSubject, string txtBody)
        {
            var mMailMessage = new System.Net.Mail.MailMessage();

            foreach(MailAddress ma in txtTo)
            {
                mMailMessage.To.Add(ma);
            }
            mMailMessage.From = txtFrom;
            mMailMessage.Subject = txtSubject;
            mMailMessage.Body = txtBody;
            mMailMessage.IsBodyHtml = true;
            mMailMessage.Priority = System.Net.Mail.MailPriority.Normal;

            SmtpClient mSmtpClient = new SmtpClient();
            mSmtpClient.Send(mMailMessage);
        }

Open in new window

0
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 2000 total points
ID: 35021567
Unless the machine hosting your app is also a mail server then you need to supply the address/ip of your mail server (and possibly login credentials too)
0
 

Author Comment

by:newbieweb
ID: 35021716
What properties of mMailMessage do I need to set?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 2000 total points
ID: 35021815
None. The SmtpClient object is the proxy between your code and your mail server, so it needs the details:
SmtpClient mSmtpClient = new SmtpClient("your mail server", 25);
mSmtpClient.Send(mMailMessage);

Open in new window

If you need to supply credentials to the mail server you need to add the following before sending:
smtp.Credentials = new System.Net.NetworkCredential("your_username", "your_password");

Open in new window

0
 

Author Comment

by:newbieweb
ID: 35027492
Where do I add the smtp object?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 35027584
Oops, that should have said:
mSmtpClient.Credentials = new System.Net.NetworkCredential("your_username", "your_password");

Open in new window

0
 

Author Closing Comment

by:newbieweb
ID: 35028013
Thanks!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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