0

Trying to send email from 1and1 smtp server in ASP :

 MailMessage Msg = new MailMessage();
        Msg.From = new MailAddress("admin@mywebsite.com");
        Msg.To.Add("personalmail");
        SmtpClient smtp = new SmtpClient("auth.smtp.1and1.fr",465);
        smtp.Credentials = new NetworkCredential("admin@mywebsite.com", "mypassword");
        smtp.EnableSsl = true;
        try
        {
            // smtp.Send(Msg);
            smtp.Send(Msg);
            return "ok";
        }
        catch (Exception e)
        {
            return e.ToString();
        }

The code goes in the catch with the error called :"net_io_connectionclosed" Do Someone know this problem ? Regards

  • 2
    try using a different port from 465, it's deprecated. http://stackoverflow.com/questions/15796530/what-is-the-difference-between-ports-465-and-587 – ProgrammerAdept Nov 12 '16 at 23:17
  • Have you tried port 587? – Vivien Chevallier Nov 12 '16 at 23:19
  • Thanks ! Technical documentations are deprecated.https://assistance.1and1.fr/mail-c65618/boite-1and1-email-basic-c65666/logiciels-de-messagerie-c85133/serveurs-popimapsmtp-pour-configurer-une-boite-1and1-email-basicpro-a792332.html –  Nov 12 '16 at 23:27

2 Answers2

4

Hyrozen,

You have to use Port 587.

Vivien Chevallier
  • 1,492
  • 1
  • 11
  • 14
0

Hyrozen,

I had the same problem for a week, and i discover this code(i do not remember where...so the author thanks a lot). My page just have a textbox for the username and a textarea for the text and a button to send the email to contact me(that is why i put the sender the same for FROM and TO in the message):

try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress(ConfigurationManager.AppSettings["Sender"]);
                message.To.Add(ConfigurationManager.AppSettings["Sender"]);
                message.Subject = "Comentario de " + TB_nomcomplet.Text;
                message.IsBodyHtml = false;
                message.Body = TB_texteemail.Text;
                SmtpClient smtp = new SmtpClient();
                smtp.Host = ConfigurationManager.AppSettings["SmtpHost"];
                smtp.Credentials = new NetworkCredential("emailYours", "passwordYours");
                smtp.Send(message);

                LBL_messageEmail.Visible = true;
            }
            catch (Exception ex)
            {
                LBL_messageEmail.Text = "Error: " + ex.Message;
            }

And in the web.config:

<appSettings>
  <add key="SmtpHost" value="smtp.1and1.com" />
  <add key="Sender" value="emailYours" />
</appSettings>
Nirtun
  • 47
  • 10
  • Now i send and receive the emails without problem! The trick was to put the line smtp.Credentials = new NetworkCredential("emailYours","passwordYours"); Hope it will help you – Nirtun Jan 03 '17 at 09:12