C# 具有包含图像的HTML正文的日历邀请
我很难让我的图像显示为包含日历附件(iCal)的邮件的HTML正文的一部分 我试图做的是: 发送outlook可识别且包含HTML正文(也显示在outlook 2013中)的日历邀请。HTML应该内联显示页眉和页脚图像 我的代码在gmail中查看时可以正常工作,但它不会在Outlook中显示图像,而是在我希望实际显示图像的正文位置显示“header.jpg”和“footer.jpg” 我已经尝试了对这个代码库的很多修改-要么忽略日历邀请部分(然后图像工作),要么日历邀请部分工作,图像不显示,而是被双击时打开良好的“header.jpg”和“screen.jpg”文件替换。我是否可以绕过此问题并在Outlook中内联显示图像 以下是我正在使用的代码(截取的无关内容):C# 具有包含图像的HTML正文的日历邀请,c#,outlook,icalendar,mailmessage,C#,Outlook,Icalendar,Mailmessage,我很难让我的图像显示为包含日历附件(iCal)的邮件的HTML正文的一部分 我试图做的是: 发送outlook可识别且包含HTML正文(也显示在outlook 2013中)的日历邀请。HTML应该内联显示页眉和页脚图像 我的代码在gmail中查看时可以正常工作,但它不会在Outlook中显示图像,而是在我希望实际显示图像的正文位置显示“header.jpg”和“footer.jpg” 我已经尝试了对这个代码库的很多修改-要么忽略日历邀请部分(然后图像工作),要么日历邀请部分工作,图像不显示,而是
var header=newlinkedresource(“header.jpg”,MediaTypeNames.Image.Jpeg);
header.ContentId=Guid.NewGuid().ToString();
header.transferncode=transferncode.Base64;
header.ContentType=新的ContentType(“图像/jpg”);
header.ContentType.Name=“header.jpg”;
header.ContentLink=新Uri(string.Format(“cid:{0}”,header.ContentId));
var screen=newlinkedresource(“screen.jpg”,MediaTypeNames.Image.Jpeg);
screen.ContentId=Guid.NewGuid().ToString();
screen.transferncode=transferncode.Base64;
screen.ContentType=新ContentType(“image/jpg”);
screen.ContentType.Name=“screen.jpg”;
screen.ContentLink=新Uri(string.Format(“cid:{0}”,screen.ContentId));
var sb=new System.Text.StringBuilder();
var dtStart=任命开始;
var dtEnd=任命结束;
var htmlcontent=string.Format(“”)+
"" +
"" +
"" +
“粗体可以正常工作,但页眉和页脚不起作用!/strong>”+
“
”+
"" +
""
);
var plaincontent=String.Format(“snip-snip”);
var av1=AlternateView.CreateAlternateViewFromString(htmlcontent,新内容类型(“text/html”);
av1.LinkedResources.Add(头);
av1.LinkedResources.Add(屏幕);
b.附录(“开始:VCALENDAR”);
sb.AppendLine(“版本:2.0”);
sb.附录(“方法:请求”);
某人加了一句话(“开始:VEVENT”);
某人追加电话(请求联系电子邮件);
sb.附录(“类别:公共”);
AppendLine(string.Format(“创建:{0:yyyyMMddTHHmmss}”,DateTime.Now));
sb.附录行(“说明:”+普通内容);
sb.AppendLine(“X-ALT-DESC;FMTTYPE=text/html:+htmlcontent”);
AppendLine(string.Format(“DTSTART:{0:yyyymmddthhmmsz}”,DTSTART.ToUniversalTime());
AppendLine(string.Format(“DTEND:{0:yyyymmddthhmmsz}”,DTEND.ToUniversalTime());
AppendLine(string.Format(“DTSTAMP:{0:yyyymmddthhmmsz}”,DateTime.Now.ToUniversalTime());
sb.AppendLine(“组织者;CN=\”组织者\“:邮件收件人:+”TheOrganizer@foobar.com");
sb.追加行(“顺序:0”);
sb.附录行(“UID:+请求.电子邮件通知UniqueID”);
sb.AppendLine(“位置:“+request.LOCATION+”:“+request.LocationInformation”);
sb.附录(“摘要;语言=美国:”+“删除”);
某人附言(BEGIN:VALARM);
sb.附加线(“触发器:-PT1440M”);
某人追加命令(“动作:显示”);
sb.附录(“说明:提醒”);
某人附言(“结束:瓦勒姆”);
某人附言(“结束:VEVENT”);
sb.附录(“结束:VCALENDAR”);
var icsView=AlternateView.CreateAlternateViewFromString(sb.ToString(),新内容类型(“文本/日历”);
var message=new MailMessage();
message.AlternateViews.Add(body);
message.AlternateViews.Add(icsView);
返回消息;
有什么根本性的错误吗?这看起来应该非常简单和直接。我已经用普通电子邮件多次这样做了,但是outlook似乎不喜欢HTML替代视图主体中带有图像的.ics附件。HTML正文工作正常(以粗体显示),但嵌入的图片却无法显示
我曾尝试使用base64手动编码图像,但毫无帮助。我尝试过在htmlContent变量中使用和不使用HTML标题标记,但也没有任何区别
这不应该这么难-我错过了什么
编辑:这是谷歌的消息来源。这在谷歌浏览器窗口中运行良好(显示正常)。不幸的是,在Outlook中,该消息不起作用。。。可能exchange服务器正在禁止内部邮件的映像?这是一件事吗
Delivered-To: snip@gmail.com
Received: by 10.182.167.74 with SMTP id zm10csp2847908obb;
Fri, 7 Oct 2016 15:42:14 -0700 (PDT)
X-Received: by 10.37.171.105 with SMTP id u96mr17483671ybi.63.1475880134797;
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Return-Path: <snip@snip.com>
Received: from msg12.snip.com (msg12.snip.com. [192.195.66.28])
by mx.google.com with ESMTPS id q11si2985157ywc.340.2016.10.07.15.42.14
for <snip@gmail.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Received-SPF: pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) client-ip=192.195.66.28;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) smtp.mailfrom=snip@snip.com
Received: from int11.snip.pvt (int11.snip.pvt [153.6.62.222]) by msg12.snip.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgC5a022486 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com (snip.com [snip]) by int11.snip.pvt (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgBAv016400 for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com with Microsoft SMTPSVC(7.5.7601.17514);
Fri, 7 Oct 2016 18:42:12 -0400
MIME-Version: 1.0
From: snip <snip@snip.com>
To: snip@gmail.com
Date: 7 Oct 2016 18:42:12 -0400
Content-Type: multipart/alternative; boundary=--boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Message-ID: <5U9T3T00000050@snip.com>
X-OriginalArrivalTime: 07 Oct 2016 22:42:12.0895 (UTC) FILETIME=[0BC44AF0:01D220EC]
X-Flow-Control: Sendmail Flow Controller v2.2.5 int11.snip.pvt u97MgBAv016400
X-Flow-Control-Info: class=Default rcpts=1 size=37636
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: multipart/related; boundary=--boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac; type="text/html"
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<img src=3D"cid:443ba735-6376-45a1-a5af-6c679321baa2"/><div><strong>The bol=
d works fine, but the header and footer don't work!</strong></div><br /><di=
v><img src=3D"cid:145c43b0-da9e-40c4-b149-3a149fbc4503"/></div>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <443ba735-6376-45a1-a5af-6c679321baa2>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <145c43b0-da9e-40c4-b149-3a149fbc4503>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac--
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: text/calendar
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KTUVUSE9EOlJFUVVFU1QNCkJFR0lOOlZFVkVO
VA0KSmRyYWhsQGdtYWlsLmNvbQ0KQ0xBU1M6UFVCTElDDQpDUkVBVEVEOjIwMTYxMDA3VDE4NDIx
MQ0KREVTQ1JJUFRJT046DQpYLUFMVC1ERVNDO0ZNVFRZUEU9dGV4dC9odG1sOjxpbWcgc3JjPSJj
aWQ6NDQzYmE3MzUtNjM3Ni00NWExLWE1YWYtNmM2NzkzMjFiYWEyIi8+PGRpdj48c3Ryb25nPlRo
ZSBib2xkIHdvcmtzIGZpbmUsIGJ1dCB0aGUgaGVhZGVyIGFuZCBmb290ZXIgZG9uJ3Qgd29yayE8
L3N0cm9uZz48L2Rpdj48YnIgLz48ZGl2PjxpbWcgc3JjPSJjaWQ6MTQ1YzQzYjAtZGE5ZS00MGM0
LWIxNDktM2ExNDlmYmM0NTAzIi8+PC9kaXY+DQpEVFNUQVJUOjIwMTYxMDI0VDE0MDAwMFoNCkRU
RU5EOjIwMTYxMDI0VDE4MDAwMFoNCkRUU1RBTVA6MjAxNjEwMDdUMjI0MjExWg0KT1JHQU5JWkVS
O0NOPSJEaXNuZXkgUmVmcmVzaCBUZWFtIjptYWlsdG86RGlzbmV5LlJlZnJlc2guVGVhbUBkaXNu
ZXkuY29tDQpTRVFVRU5DRTowDQpVSUQ6NGE5YjczNWQtOTQwYS00Mzk0LTkzODItMzMyMmQxNDg0
MTBiDQpMT0NBVElPTjpPcmxhbmRvIDogDQpTVU1NQVJZO0xBTkdVQUdFPWVuLXVzOkNvbXB1dGVy
IFJlZnJlc2ggQXBwb2ludG1lbnQNCkJFR0lOOlZBTEFSTQ0KVFJJR0dFUjotUFQxNDQwTQ0KQUNU
SU9OOkRJU1BMQVkNCkRFU0NSSVBUSU9OOlJlbWluZGVyDQpFTkQ6VkFMQVJNDQpFTkQ6VkVWRU5U
DQpFTkQ6VkNBTEVOREFSDQo=
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042--
交付给:snip@gmail.com
收到日期:10.182.167.74,SMTP id为zm10csp2847908obb;
2016年10月7日星期五15:42:14-0700(PDT)
X-Received:10.37.171.105,SMTP id为u96mr17483671ybi.63.1475880134797;
2016年10月7日星期五15:42:14-0700(PDT)
返回路径:
收到:来自msg12.snip.com(msg12.snip.com。[192.195.66.28])
通过mx.google.com使用ESMTPS id q11si2985157ywc.340.2016.10.07.15.42.14
对于
(版本=TLS1_2密码=ECDHE-RSA-AES128-GCM-SHA256位=128/128);
2016年10月7日星期五15:42:14-0700(PDT)
收到SPF:pass(google.com:domain of ofsnip@snip.com指定192.195.66.28为允许的发送方)客户端ip=192.195.66.28;
认证结果:mx.google.com;
spf=pass(google.com:domain of ofsnip@snip.com将192.195.66.28指定为允许的发件人)smtp.mailfrom=snip@snip.com
msg12.snip.com(Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2)从int11.snip.pvt(int11.snip.pvt[153.6.62.222])收到,ESMTP id为u97MgC5a022486(版本=TLSv1.2密码=ECDHE-RSA-AES256-GCM-SHA384位=256验证=失败);2016年10月7日星期五22:42:12 GMT
接收:int11.snip.pvt(Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2)从snip.com(snip.com[snip])收到,ESMTP id为u97MgBAv016400,用于:;2016年10月7日星期五22:42:12 GMT
收到:来自snip.com和Microsoft SMTPSVC(7.5.7601.17514);
2016年10月7日星期五18:42:12-0400
MIME版本:1.0
发件人:剪
致:snip@gmail.co
Delivered-To: snip@gmail.com
Received: by 10.182.167.74 with SMTP id zm10csp2847908obb;
Fri, 7 Oct 2016 15:42:14 -0700 (PDT)
X-Received: by 10.37.171.105 with SMTP id u96mr17483671ybi.63.1475880134797;
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Return-Path: <snip@snip.com>
Received: from msg12.snip.com (msg12.snip.com. [192.195.66.28])
by mx.google.com with ESMTPS id q11si2985157ywc.340.2016.10.07.15.42.14
for <snip@gmail.com>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Fri, 07 Oct 2016 15:42:14 -0700 (PDT)
Received-SPF: pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) client-ip=192.195.66.28;
Authentication-Results: mx.google.com;
spf=pass (google.com: domain of snip@snip.com designates 192.195.66.28 as permitted sender) smtp.mailfrom=snip@snip.com
Received: from int11.snip.pvt (int11.snip.pvt [153.6.62.222]) by msg12.snip.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgC5a022486 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com (snip.com [snip]) by int11.snip.pvt (Sentrion-MTA-4.3.1/Sentrion-MTA-4.2.2) with ESMTP id u97MgBAv016400 for <snip@gmail.com>; Fri, 7 Oct 2016 22:42:12 GMT
Received: from snip.com with Microsoft SMTPSVC(7.5.7601.17514);
Fri, 7 Oct 2016 18:42:12 -0400
MIME-Version: 1.0
From: snip <snip@snip.com>
To: snip@gmail.com
Date: 7 Oct 2016 18:42:12 -0400
Content-Type: multipart/alternative; boundary=--boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Message-ID: <5U9T3T00000050@snip.com>
X-OriginalArrivalTime: 07 Oct 2016 22:42:12.0895 (UTC) FILETIME=[0BC44AF0:01D220EC]
X-Flow-Control: Sendmail Flow Controller v2.2.5 int11.snip.pvt u97MgBAv016400
X-Flow-Control-Info: class=Default rcpts=1 size=37636
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: multipart/related; boundary=--boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac; type="text/html"
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<img src=3D"cid:443ba735-6376-45a1-a5af-6c679321baa2"/><div><strong>The bol=
d works fine, but the header and footer don't work!</strong></div><br /><di=
v><img src=3D"cid:145c43b0-da9e-40c4-b149-3a149fbc4503"/></div>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <443ba735-6376-45a1-a5af-6c679321baa2>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <145c43b0-da9e-40c4-b149-3a149fbc4503>
----boundary_1_306bb8e7-fb92-4eab-bf5c-b7393cf499ac--
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042
Content-Type: text/calendar
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KTUVUSE9EOlJFUVVFU1QNCkJFR0lOOlZFVkVO
VA0KSmRyYWhsQGdtYWlsLmNvbQ0KQ0xBU1M6UFVCTElDDQpDUkVBVEVEOjIwMTYxMDA3VDE4NDIx
MQ0KREVTQ1JJUFRJT046DQpYLUFMVC1ERVNDO0ZNVFRZUEU9dGV4dC9odG1sOjxpbWcgc3JjPSJj
aWQ6NDQzYmE3MzUtNjM3Ni00NWExLWE1YWYtNmM2NzkzMjFiYWEyIi8+PGRpdj48c3Ryb25nPlRo
ZSBib2xkIHdvcmtzIGZpbmUsIGJ1dCB0aGUgaGVhZGVyIGFuZCBmb290ZXIgZG9uJ3Qgd29yayE8
L3N0cm9uZz48L2Rpdj48YnIgLz48ZGl2PjxpbWcgc3JjPSJjaWQ6MTQ1YzQzYjAtZGE5ZS00MGM0
LWIxNDktM2ExNDlmYmM0NTAzIi8+PC9kaXY+DQpEVFNUQVJUOjIwMTYxMDI0VDE0MDAwMFoNCkRU
RU5EOjIwMTYxMDI0VDE4MDAwMFoNCkRUU1RBTVA6MjAxNjEwMDdUMjI0MjExWg0KT1JHQU5JWkVS
O0NOPSJEaXNuZXkgUmVmcmVzaCBUZWFtIjptYWlsdG86RGlzbmV5LlJlZnJlc2guVGVhbUBkaXNu
ZXkuY29tDQpTRVFVRU5DRTowDQpVSUQ6NGE5YjczNWQtOTQwYS00Mzk0LTkzODItMzMyMmQxNDg0
MTBiDQpMT0NBVElPTjpPcmxhbmRvIDogDQpTVU1NQVJZO0xBTkdVQUdFPWVuLXVzOkNvbXB1dGVy
IFJlZnJlc2ggQXBwb2ludG1lbnQNCkJFR0lOOlZBTEFSTQ0KVFJJR0dFUjotUFQxNDQwTQ0KQUNU
SU9OOkRJU1BMQVkNCkRFU0NSSVBUSU9OOlJlbWluZGVyDQpFTkQ6VkFMQVJNDQpFTkQ6VkVWRU5U
DQpFTkQ6VkNBTEVOREFSDQo=
----boundary_0_8278962b-71cf-4ca1-9a64-5fb9629f2042--
private String senderAddress = "YOUR EMAIL ADDRESS";
private final String password = "YOUR EMAIL PASSWORD";
public static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd'T'HHmm'00'");
public static SimpleDateFormat dateParser = new SimpleDateFormat("dd-MM-yyyy HH:mm");
public static SimpleDateFormat dateFormater = new SimpleDateFormat("dd-MM-yyyy");
public String getSenderAddress() {
return senderAddress;
}
public String getPassword() {
return password;
}
public Session getMailSession() {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
return Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(getSenderAddress(), getPassword());
}
});
}
public String newSend(Invitation invitation, String methodType) {
String UID = null;
// register the text/calendar mime type
MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
mimetypes.addMimeTypes("text/calendar ics ICS");
// register the handling of text/calendar mime type
MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");
MimeMessage message = new MimeMessage(getMailSession());
try {
message.setFrom(new InternetAddress(senderAddress));
message.setSubject(invitation.getSubject());
message.addRecipient(Message.RecipientType.TO, new InternetAddress(invitation.getTo()));
Multipart multipart = new MimeMultipart("mixed");
invitation.setDescription(getHtmlWithEncodedImages(multipart,invitation));
Multipart mpMixedAlternative = newChild(multipart, "alternative");
// html part
BodyPart messageBodyPart = buildHtmlTextPart(invitation);
mpMixedAlternative.addBodyPart(messageBodyPart);
// Add part two, the calendar
BodyPart calendarPart = buildCalendarPart(invitation, methodType);
calendarPart.setDisposition(BodyPart.INLINE);
mpMixedAlternative.addBodyPart(calendarPart);
addAttachment(multipart);
// Put the multipart in message
message.setContent(multipart);
// send the message
Transport transport = getMailSession().getTransport("smtp");
transport.connect();
transport.sendMessage(message, message.getAllRecipients());
transport.close();
UID = invitation.getTo() + "" + invitation.getStartdate().toString() + "" + invitation.getStarttime();
} catch (Exception e) {
//TODO logger log exception
}
return UID;
}
private void addAttachment(Multipart multipart) {
MimeBodyPart mbpAttachment = new MimeBodyPart();
File file=new File("C:/users/ishan.juneja/Desktop/temp.txt");
DataSource datasource=new FileDataSource(file);
try {
mbpAttachment.setDataHandler(new DataHandler(datasource));
mbpAttachment.setDisposition(BodyPart.ATTACHMENT);
mbpAttachment.setFileName("temp.txt");
multipart.addBodyPart(mbpAttachment);
} catch (MessagingException e) {
// TODO logger log exception
}
}
public String uploadImage(MultipartFile file){
byte[] bytes;
try {
String path = System.getProperty("catalina.home");
File dir = new File(path+"/tmpFiles");
if(!dir.isDirectory()){
dir.mkdir();
}
bytes = file.getBytes();
File serverfile = new File(dir.getAbsolutePath()+"/"+file.getName()+Math.random()+".png");
BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverfile));
stream.write(bytes);
stream.close();
System.out.println("file uploaded "+serverfile.getAbsolutePath());
String hostname="Unknown";
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e1) {
e1.printStackTrace();
}
return "{\"location\" : \"http://"+hostname+":8080/emailinvitation/image/path/"+serverfile.getName()+"\"}";
} catch (IOException e) {
}
return "{\"location\":\"http://localhost:8080/emailinvitation/image/path/unknown.png\"}";
}
private Multipart newChild(Multipart parent, String alternative) {
MimeMultipart child = new MimeMultipart(alternative);
MimeBodyPart mbp = new MimeBodyPart();
try {
parent.addBodyPart(mbp);
mbp.setContent(child);
} catch (MessagingException e) {
// TODO logger log exception
}
return child;
}
private BodyPart buildCalendarPart(Invitation invitation, String methodType) throws Exception {
Date date1 = dateParser.parse(dateFormater.format(invitation.getStartdate()) + " " + invitation.getStarttime());
String startDate = timeZoneToUTC(invitation, date1);
Date date2 = dateParser.parse(dateFormater.format(invitation.getEnddate()) + " " + invitation.getEndtime());
String endDate = timeZoneToUTC(invitation, date2);
BodyPart calendarPart = new MimeBodyPart();
String calendarContent = "BEGIN:VCALENDAR\n" + "METHOD:" + methodType + "\n" + "PRODID: BCP - Meeting\n"
+ "VERSION:2.0\n" + "X-WR-TIMEZONE:" + invitation.getTimezone() + "\n" + "BEGIN:VEVENT\n" + "DTSTAMP:"
+ startDate + "Z\n" + "DTSTART:" + startDate + "Z\n" + "DTEND:" + endDate + "Z\n"
+ "SUMMARY:test request\n" + "UID:" + invitation.getTo() + "" + startDate + "\n"
+ "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=FALSE:MAILTO:" + invitation.getTo() + "\n"
+ "ORGANIZER:MAILTO:" + senderAddress + "\n" + "LOCATION:Test\n" + "SEQUENCE:0\n"
+ "PRIORITY:5\n" + "CLASS:PUBLIC\n" + "STATUS:CONFIRMED\n" + "TRANSP:OPAQUE\n" + "BEGIN:VALARM\n"
+ "ACTION:DISPLAY\n" + "DESCRIPTION:REMINDER\n" + "TRIGGER;RELATED=START:-PT00H15M00S\n"
+ "END:VALARM\n" + "END:VEVENT\n" + "END:VCALENDAR";
calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
calendarPart.setContent(calendarContent, "text/calendar;method=" + methodType);
return calendarPart;
}
private BodyPart buildHtmlTextPart(Invitation invitation) {
MimeBodyPart descriptionPart = new MimeBodyPart();
String content = invitation.getDescription();
try {
descriptionPart.setContent(content, "text/html; charset=utf-8");
} catch (MessagingException e) {
// TODO logger log exception
}
return descriptionPart;
}
private void addImages(Multipart parent,String filename) {
MimeBodyPart mbpAttachment = new MimeBodyPart();
try {
File file = new File("C:\\apache-tomcat-8.5.24\\tmpFiles\\"+filename);
FileDataSource ds = new FileDataSource(file);
mbpAttachment.setDataHandler(new DataHandler(ds));
mbpAttachment.setDisposition(BodyPart.INLINE);
mbpAttachment.setHeader("Content-ID", filename);
mbpAttachment.setFileName(filename);
parent.addBodyPart(mbpAttachment);
} catch (Exception e) {
//TODO logger log exception
}
}
private String timeZoneToUTC(Invitation invitation, Date date) {
ZoneId zone = ZoneId.of(invitation.getTimezone());
String date1 = dateParser.format(date);
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm").withZone(zone);
ZonedDateTime utc = ZonedDateTime.parse(date1, fmt).withZoneSameInstant(ZoneId.of("UTC"));
Timestamp sqlTs = Timestamp.valueOf(utc.toLocalDateTime());
return dateFormat.format(sqlTs);
}
public String getHtmlWithEncodedImages(Multipart parent,Invitation invitation) {
String temp = invitation.getDescription();
String html="<html><body>"+invitation.getDescription()+"</body></html>";
Document document = Jsoup.parse(html);
Elements allElements=document.body().getElementsByTag("img");
for (Element element : allElements) {
String elementstring=element.toString();
String tempfilename = elementstring.substring(elementstring.indexOf("file"));
String filename=tempfilename.substring(0,tempfilename.indexOf('"'));
temp=temp.replace(elementstring.substring(elementstring.indexOf('"'), elementstring.lastIndexOf('"')),"\"cid:"+filename);
addImages(parent, filename);
}
System.out.println("--++--"+temp);
return temp;
}