简体   繁体   English

从1and1 SMTP服务器发送电子邮件

[英]Email sending from 1and1 SMTP server

Trying to send email from 1and1 smtp server in ASP : 尝试从ASP中的1and1 smtp服务器发送电子邮件:

 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 ? 该代码的错误之处在于:“ net_io_connectionclosed”有人知道这个问题吗? Regards 问候

Hyrozen, Hyrozen,

You have to use Port 587. 您必须使用端口587。

Hyrozen, 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): 我的页面只有一个用于用户名的文本框和一个用于文本的文本区域,以及一个用于发送电子邮件以与我联系的按钮(这就是为什么我在邮件中将发件人的FROM和TO设置为相同的原因):

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: 并在web.config中:

<appSettings>
  <add key="SmtpHost" value="smtp.1and1.com" />
  <add key="Sender" value="emailYours" />
</appSettings>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM