我正在尝试在电子邮件中创建一个facebook分享按钮,并通过C#分享附加的视频。
首先,我已将电子邮件附加到我要发送的视频中。 但我不能通过C#创建我想分享视频的facebook按钮。
到目前为止,您可能会找到我的源代码:
public static string logopath = Path.Combine(Application.StartupPath, "logo.png");
public static string videopath = Path.Combine(Application.StartupPath, "test.mp4");
private void button1_Click_1(object sender, EventArgs e)
{
string usermail = textBox1.Text;
bool isUsermailNull = usermail.Equals("");
Console.Out.WriteLine("The variable is " + isUsermailNull);
if (isUsermailNull.Equals(false))
{
try
{
MailAddress m = new MailAddress(usermail);
try
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
message.From = new MailAddress("myemailaccount@gmail.com");
message.To.Add(new MailAddress(usermail));
message.Subject = "SUBJECT";
message.IsBodyHtml = true;
Attachment inlineLogo = new Attachment(logopath);
Attachment inlineLogo2 = new Attachment(videopath);
message.Attachments.Add(inlineLogo);
message.Attachments.Add(inlineLogo2);
string contentID = "Image";
string contentID2 = "Image2";
inlineLogo.ContentId = contentID;
inlineLogo2.ContentId = contentID2;
//To make the image display as inline and not as attachment
inlineLogo.ContentDisposition.Inline = true;
inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inlineLogo2.ContentDisposition.Inline = true;
inlineLogo2.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
//To embed image in email
//string pass = "123456";
message.Body = "<html><body> <h1 align=\"center\"><img src=\"cid:" + contentID + "\"> </h1><video width=\"400\" controls><source src=\"cid:" + contentID2 + "\" type=\"video/mp4\">Your browser does not support HTML5 video.</video> <h1 align=\"center\">Project</h1> "
+ " <h2 align=\"center\"> NameofProject </h2><h2 align=\"center\">You may find attached your video</h2><div id=\"fb-root\"></div><script>(function(d, s, id) {var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = \"//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.7\"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div class=\"fb-video\" data-href=\"cid:" + contentID2 + "\" data-width=\"500\" data-show-text=\"false\"><div class=\"fb-xfbml-parse-ignore\"><blockquote cite=\"cid:" + contentID2 + "\"><a href=\"cid:" + contentID2 + "\" >Share with your Friends</a><p>Project</p>Created by <a href=\"https://www.facebook.com/mysite/?fref=ts&ref=br_tf\">MyProject</a> </blockquote> </div> </div> <h3 align=\"center\"> Thank you</h3> <h2 align=\"center\">Details</h2> <h2 align=\"center\"> Mail us : myemailaccount@gmail.com</h2> </body></html>";
smtp.Port = 587;
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential("myemailaccount@gmail.com", "password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Timeout = 5000000;
smtp.Send(message);
}
catch (Exception ex)
{
MessageBox.Show("err: " + ex.Message);
}
this.Close();
}
catch (FormatException)
{
MessageBox.Show("You haven't put correct email address. Try again!!!!");
}
//Kill all on screen keyboards
Process[] oskProcessArray = Process.GetProcessesByName("TabTip");
foreach (Process onscreenProcess in oskProcessArray)
{
onscreenProcess.Kill();
}
}
else
{
MessageBox.Show("The textbox is null. Please insert an appropriate email address");
}
}
提前谢谢
答案 0 :(得分:0)
您需要使用包含您的文件的网址添加hmtl <a>
正文,例如:
<a href="http://www.facebook.com/sharer/sharer.php?u=**MYURL**" style="color:#202020;font-family:Arial;font-size:12px;font-weight:normal;line-height:normal;text-align:center;text-decoration:none" class="gmail_msg" target="_blank" data-saferedirecturl="https://www.google.com/url?q=http://www.facebook.com/sharer/sharer.php?**CONFIDENTIAL**">Share in Facebook</a>