Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help with sending email from MS Windows server 2008

Posted on 2012-08-21
21
Medium Priority
?
187 Views
Last Modified: 2012-10-03
Hello,

This is followup to issue: http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_27806917.html

Can someone please assist me further on this issue. My application will de deployed in to ebderver 2008, is there a way to avoid using my personal email address to send emails?

Thanks,

Victor
0
Comment
Question by:vcharles
  • 12
  • 9
21 Comments
 
LVL 9

Expert Comment

by:teebon
ID: 38315710
Hi Victor,

You may use IIS SMTP to send out email :

http://technet.microsoft.com/en-us/library/cc772058%28v=ws.10%29.aspx
0
 

Author Comment

by:vcharles
ID: 38316694
Hi,

Can it be done from the application using .net tools or are there any third partzy controls that allow you to do this from the application side?

Thanks,

Victor
0
 
LVL 9

Expert Comment

by:teebon
ID: 38316724
yes, you can send email from your application once you have setup this smtp. you can utilize the smtp ip and port number that you setup
0
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

 

Author Comment

by:vcharles
ID: 38316860
Once I setup the server, what is the code syntax to send an email from my application?
Thanks,

Victor
0
 
LVL 9

Expert Comment

by:teebon
ID: 38319144
Try the following, I've commented the credentials as by default no credentials is required if you accessing the IIS SMTP from the localhost:

using System.Net.Mail

        MailMessage msgMail = new MailMessage();

        MailMessage myMessage = new MailMessage();
        myMessage.From = new MailAddress("sender's email","sender`s name");
        myMessage.To.Add("recipient's email");
        myMessage.Subject = "Subject";
        myMessage.IsBodyHtml = true;

        myMessage.Body = "Message Body";


        SmtpClient mySmtpClient = new SmtpClient();
        //System.Net.NetworkCredential myCredential = new System.Net.NetworkCredential("email", "password");
        mySmtpClient.Host = "localhost";
        //mySmtpClient.Port = "your IIS smtp port (if other than 25)";
        mySmtpClient.UseDefaultCredentials = true;
        //mySmtpClient.Credentials = myCredential;
        mySmtpClient.ServicePoint.MaxIdleTime = 1;

        mySmtpClient.Send(myMessage);
        myMessage.Dispose();

Open in new window

0
 

Author Comment

by:vcharles
ID: 38319198
Thank you, will test it and get back to you.
0
 

Author Comment

by:vcharles
ID: 38319325
Hi,

Just realised your code is in C#, do you have the vb.net version? Also this is a web aplication.

Thanks,

Victor
0
 
LVL 9

Expert Comment

by:teebon
ID: 38319382
You can use this in the ASP.NET code behind:

Dim Message As MailMessage = New MailMessage()
Dim Smtp As New SmtpClient()

'-- Build Message
Message.From = New MailAddress("larryking@cnn.com", "Larry King")
Message.To.Add(New MailAddress("oprah@oprah.com", "Oprah"))
Message.IsBodyHtml = False

Message.Subject = "Come on My Show Soon"
Message.Body = "Please be a guest on my show. - Larry"
'-- Send Message
'-- each web host is different 
'-- (adjust next 2 lines accordingly)
Smtp.Host = "localhost"
Smtp.DeliveryMethod = SmtpDeliveryMethod.Network
Smtp.Send(Message)

Open in new window

0
 

Author Comment

by:vcharles
ID: 38319465
Hi,

I am trying to send the email from the local webserver that comes with VS 2010 using the following code:

  Smtp.Host = "localhost:63969"
  Smtp.DeliveryMethod = SmtpDeliveryMethod.Network

But still getting an error on line: Smtp.Send(Message)

Any ideas what I am doing wrong?

Victor
0
 
LVL 9

Expert Comment

by:teebon
ID: 38319547
Try the following:

Smtp.Host = "localhost"
Smtp.Port = "63969"

Please also paste the detailed error message that you are getting
0
 

Author Comment

by:vcharles
ID: 38319568
It still does not work, error message is: Failure sending mail.
I will deploy the application to the windows server and see if it works, but I think it should also work from the sever that comes with VS2010.
0
 
LVL 9

Accepted Solution

by:
teebon earned 2000 total points
ID: 38319735
Can you test whether your smtp server works with telnet:

http://thedaneshproject.com/posts/send-mail-through-smtp-using-telnet/

Also, try to get the inner exception and stack trace:
Try

'Your code here

Catch ex As Exception
Console.WriteLine(ex.InnerException)
Console.WriteLine(ex.StackTrace)
End Try

Open in new window

0
 

Author Comment

by:vcharles
ID: 38319760
Dumb question....How do I see the console?

Code executes but the console does not appear.
0
 
LVL 9

Expert Comment

by:teebon
ID: 38319802
I assume you are debugging in Visual Studio,
Go to Debug > Windows > Output

The value should output into the Output window.
0
 

Author Comment

by:vcharles
ID: 38320404
I see a message "connected to localhost" at the bottom of the form but email was not sent
0
 

Author Comment

by:vcharles
ID: 38332249
Help! Any ideas why this is till not working?
0
 
LVL 9

Expert Comment

by:teebon
ID: 38335737
Can you check whether your firewall or antivirus is blocking port 25 TCP outgoing?
0
 

Author Comment

by:vcharles
ID: 38337492
Hi,
I received the following error multiple times.
A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll
0
 

Author Comment

by:vcharles
ID: 38367360
How do i check whether my firewall or antivirus is blocking port 25 TCP outgoing?
0
 
LVL 9

Expert Comment

by:teebon
ID: 38367373
0
 

Author Comment

by:vcharles
ID: 38379769
No, I have not tried it, will look more into it when I return to the ofice by the end of the week.
Thanks.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…

579 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