Send Email Using .NET - Not So Easy

After about a year, I was having problems trying to send and receive email programmatically using Visual C #. None of the hundreds I've found on the internet have ever worked. And no, I'm not just copying and pasting. I go through the code and change / add / remove as needed.

Can someone PLEASE help me figure this out. I am trying to finish what was supposed to be a simple program that I started doing last year and it turned out to be almost impossible for me to figure out.

Honestly, I don't know what to do next. The documentation doesn't give me any useful information because none of them have ever worked. I've given sample code to others and it works for them, but not me! How it works?

I don't know if SENDING mail depends on the security / firewall settings my computer has or not. But anyway, I got to the point where I temporarily disabled all security and firewall settings to see if it would send an email.

I don't have any more code because I just started trying to do it again and I would really appreciate it if someone could help me with this.

So, all I am trying to do is:

Create a simple form with two buttons and a text box. (done of course) button1

checks for email presence (but only displays subject and sender in message box, doesn't load message) button2

sends content of textBox1 to " username@bluebottle.com

"

My server settings:

Username    username@bluebottle.com
Password    ***********
IMAP/POP Server (Incoming):     mail.bluebottle.com
SMTP Server     (Outgoing):     mail.bluebottle.com

SMTP should be port 25, 26 or 587
POP3 should be port 110, using SSL 995
IMAP should be port 143, using SSL 993

      


Thank you for taking the time to read. If I don't explain anything clearly, please tell me and I will try to make more sense out of it for you.
+2


source to share


2 answers


Nothing. I just figured it out for myself. It's as easy as 123! or is it ABC? I forget how it happens. Anyone who might be interested or should know how to send email in C #, this is what worked for ME:


string Sender     = "username@domain.com";

string Username   = "username";
string Password   = "********";

string Recipient  = "username@domain.com";

string Subject    = "Enter subject here.";
string Message    = "Enter message here.";

string Host       = "mail.server.com";
int Port          = 26;

using(MailMessage Mail = 
      new MailMessage(
      Sender,
      Recipient))
using (SmtpClient SmtpMail =
       new SmtpClient(
       Host,
       Port))
{
  Mail.Subject = Subject;
  Mail.Body    = Message;

  SmtpMail.EnableSsl = true;

  SmtpMail.Credentials =
        new System.Net.NetworkCredential(
        Username,
        Password);

  SmtpMail.Send(Mail);
}

      




Note that the following using a directive must be listed at the top of the document:
using System.Net.Mail;

      

Edit: Using docos template: http://msdn.microsoft.com/en-us/library/yh598w02(VS.71).aspx

+5


source


Since this year, Microsoft has provided pop3 and SMTP support to all Hotmail users.

  • POP3 server: pop3.live.com (port 995)
  • SMTP server: smtp.live.com (port 25) {Note: if port 25 is blocked by your network or your ISP, you can set the SMTP port to 587 using TLS or SSL Encryption depending on the client to use}


More information: http://windowslivehelp.com/solutions/settings/archive/2009/01/06/send-and-receive-windows-live-hotmail-emails-from-a-mail-client.aspx

+2


source







All Articles