I'm trying to send an animated GIF via e-mail using a Gmail account. I can send normal picture with this code:
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("my adress", "Kinomaton");
mail.To.Add(richTextBox1.Text);
mail.Subject = Kinomaton.Properties.Settings.Default.objet;
mail.Body = Kinomaton.Properties.Settings.Default.mail;
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment(@"F:\gif_temp\gif" + (Kinomaton.Properties.Settings.Default.folder - 1) + "\\gif_final3.jpg");
mail.Attachments.Add(attachment);
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("my adress", "my password");
SmtpServer.EnableSsl = true;
SmtpServer.Timeout = 500000000;
SmtpServer.Send(mail);
The problem is that when I try to replace the .jpg file by a .gif file, it doesn't work. Anyone can help me please ?
答案 0 :(得分:1)
第1步:将gif上传到imgur
第2步:发送包含指向您的gif链接的电子邮件
第3步:派对
这将确保收件人可以实际查看gif。正如评论中所提到的,很多电子邮件客户端都不会显示gif。
*编辑* 要通过代码上传文件:
using (var w = new WebClient())
{
var values = new NameValueCollection
{
{ "key", "<api-key>" },
{ "image", Convert.ToBase64String(File.ReadAllBytes(@"<file>")) }
};
byte[] response = w.UploadValues("http://imgur.com/api/upload.xml", values);
Console.WriteLine(XDocument.Load(new MemoryStream(response)));
}
输出将告诉您该文件的链接在Imgur上,以便您可以将其发送给任何人。