Solved

Need my ASP.NET MVC site to send an email

Posted on 2011-03-02
7
326 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 36
C# Offline Apllication 5 55
VB.Net How to Exit Sub - Exit Form??? 5 51
Counting connections to SQL Server through C# 3 29
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now