Solved

Need my ASP.NET MVC site to send an email

Posted on 2011-03-02
7
327 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
  • 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 500 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 500 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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 44
Install Problem 13 29
Need to start a web service from Visual Studio 2015 Pro 2 22
Help with exporting to excel 4 26
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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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