发送邮件失败,显示 Base64字符数组的无效长度
winform程序,发送邮件失败,邮箱是163企业邮箱,但是在foxmail中能发送!
如果换成另外一个163免费邮箱,就没问题!!
代码如下
=======================================
using System.Net.Mail;
try
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.163vip.com";
client.Port = 25;
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("myemial01@shieldwood.com", "*****");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mail = new MailMessage();
mail.Subject = "subject";
MailAddress from = new MailAddress("myemial01@shieldwood.com", "myemial01@shieldwood.com");
mail.From = from;
mail.Body = "email body";
mail.SubjectEncoding = System.Text.Encoding.Default;
mail.BodyEncoding = System.Text.Encoding.Default;
mail.Priority = MailPriority.Normal;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
client.Send(mail);
}
catch (Exception ex)
{
string strErr = ex.Message;
if (ex.InnerException != null)
strErr = strErr + "\r\n\r\n" + ex.InnerException.Message; //这里Base64字符数组的无效长度
//strErr 显示: 发送邮件失败 Base64字符数组的无效长度
}
搞不懂,不知怎么回事!
------解决方案--------------------
内容
public string EncodeString(string content)
{
byte[] encrypted = Convert.FromBase64String(content);
return System.Text.ASCIIEncoding.Default.GetString(encrypted);
}
------解决方案--------------------
长度必须是4的倍数