Solved

Need my ASP.NET MVC site to send an email

Posted on 2011-03-02
7
329 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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