473,473 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

C# - Email problems

Hi all
I am having trouble with sending email via a C#2.0 application, I use
the same settings as I use in Outlook but I cannot get email to send.

I am trying to use SSL on port 465 and get the error below, If I disable
SSL and use port 587 all goes well.
I have been Googling for 2 days without success and this seems to be a
common problem.
Any help is appreciated.

Thanks.
Here is the code I am using.
MailMessage message = new MailMessage();
message.From = new MailAddress("my*******@mydomain.com");
message.Sender = new MailAddress("my*******@mydomain.com");
message.To.Add(new MailAddress("my*******@mydomain.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smtp.bizmail.yahoo.com", 465);
System.Net.NetworkCredential mc = new
System.Net.NetworkCredential("my********@mydomain. com", "mypassword");

smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mc ;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network ;
smtpClient.EnableSsl = true;

try{
smtpClient.Send(message);

}
catch(Exception e) {
System.Console.WriteLine(e.InnerException.ToString ());
}

smtpClient = null;

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

The error I get is this:

Unable to read data from the transport connection: An existing
connection was forcibly closed by the remote host.

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(S mtpReplyReader
caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(Sm tpReplyReader
caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Nov 24 '07 #1
2 2212
Here is a sample method that I use with my gmail account. The port is
different, but it should work for you with the correct port:

using System;
using System.Collections.Generic;
using System.Text;

namespace PAB.Utils
{
public static class Sender
{
public static void SendGmail(string userName, string password,
string mailFrom,
string mailTo,string subject, string
message,bool isBodyHtml)
{
System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage(mailFrom,mailTo,
subject, message);
msg.IsBodyHtml = isBodyHtml;
System.Net.NetworkCredential cred = new
System.Net.NetworkCredential(userName, password);
System.Net.Mail.SmtpClient mailClient = new
System.Net.Mail.SmtpClient("smtp.gmail.com",587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = cred;
mailClient.Send(msg);
}
}
}
--
--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com

"Eugene Vital" wrote:
Hi all
I am having trouble with sending email via a C#2.0 application, I use
the same settings as I use in Outlook but I cannot get email to send.

I am trying to use SSL on port 465 and get the error below, If I disable
SSL and use port 587 all goes well.
I have been Googling for 2 days without success and this seems to be a
common problem.
Any help is appreciated.

Thanks.
Here is the code I am using.
MailMessage message = new MailMessage();
message.From = new MailAddress("my*******@mydomain.com");
message.Sender = new MailAddress("my*******@mydomain.com");
message.To.Add(new MailAddress("my*******@mydomain.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smtp.bizmail.yahoo.com", 465);
System.Net.NetworkCredential mc = new
System.Net.NetworkCredential("my********@mydomain. com", "mypassword");

smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mc ;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network ;
smtpClient.EnableSsl = true;

try{
smtpClient.Send(message);

}
catch(Exception e) {
System.Console.WriteLine(e.InnerException.ToString ());
}

smtpClient = null;

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

The error I get is this:

Unable to read data from the transport connection: An existing
connection was forcibly closed by the remote host.

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(S mtpReplyReader
caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(Sm tpReplyReader
caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Nov 24 '07 #2
Thanks,

That is pretty much the code I am using and it doesn't work.

It appears as though it is timing out then disconnecting, I have enabled
logging but it doesn't give me anything useful.

Peter Bromberg [C# MVP] wrote:
Here is a sample method that I use with my gmail account. The port is
different, but it should work for you with the correct port:

using System;
using System.Collections.Generic;
using System.Text;

namespace PAB.Utils
{
public static class Sender
{
public static void SendGmail(string userName, string password,
string mailFrom,
string mailTo,string subject, string
message,bool isBodyHtml)
{
System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage(mailFrom,mailTo,
subject, message);
msg.IsBodyHtml = isBodyHtml;
System.Net.NetworkCredential cred = new
System.Net.NetworkCredential(userName, password);
System.Net.Mail.SmtpClient mailClient = new
System.Net.Mail.SmtpClient("smtp.gmail.com",587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = cred;
mailClient.Send(msg);
}
}
}
Nov 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Irmen de Jong | last post by:
Hi I'm trying to create e-mail content using the email.MIMEText module. It basically works, until I tried to send mail in non-ascii format. What I did, to test both iso-8859-15 and UTF-8...
5
by: Paul Cheevers | last post by:
Hi, This is driving me nuts to say the least!!!!! I am trying to send an email from some server side ASP code and the CC field is giving me some problems. The code works fine if I have one...
88
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
24
by: Arno R | last post by:
Hi all, I have a client with several shoe-shops. Customers can leave their email-address if they want to be notified when there is a sale. Input is validated with instr() I am checking for @...
2
by: Jim in Arizona | last post by:
I've made an application that is a computer problems (tickets) system. The employee goes to a web page and posts the comptuer problem they're having. Then, the IS staff goes to another webpage...
1
by: trevors_decoy | last post by:
Hi, apologies if this sort of query pops up all the time - I did spend a while searching the archives first... My website tries to protect my email address from the spam harvesters by...
4
by: lucavilla | last post by:
If you go to http://europe.nokia.com/A4305060, fill the "Enter your product code:" field with the value "0523183" and press "Go" (the ending page URL varies because there's a variable session-ID in...
0
by: RickVidallon | last post by:
Missing or Truncated Body Text in Email Application - 2 Strange Examples... There is no earthly reason why this is happening! EXAMPLES HERE: http://65.36.227.70/actmailer/ We have a...
5
by: Dave | last post by:
Hi All, I'm experiencing problems with sending mail using mail() to forwarded email accounts. The problem seems to revolve around the optional 4th argument of mail(), namely 'additional headers'....
14
by: Warren Tang | last post by:
Hi I am using the mail function to send a mail like this: $b = mail("my_real_email_address@gmail.com", "Hello from PHP", "Hi, finally sent an email successfully"); But it failed. Could you...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.