I'm trying to send a .ics file which has been generated via iCal.net. Opening the file in Outlook is fine and has the image attachment I'm trying to send via MailKit, but when sending via Mailkit, the image is not there.
BEGIN:VCALENDAR
METHOD:REQUEST
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:VEVENT
ATTACH;FMTTYPE=image/png;X-FILENAME=qrcode.png;VALUE=BINARY;ENCODING=BASE6
4:iVBORw0KGgoAAAANSUhEUgAABkAAAAZAAQMAAAAbwhzkAAAABGdBTUEAALGPC/xhBQAAAAF
zUkdCAK7OHOkAAAAGUExURQAAAP7+/soH9D0AAAYwSURBVHja7dyxcYNAEAVQPA4UugRKoTRc
GqW4BIcKNMKBcABzXu8JhIXn/UwSJ/Zt/Oea8Z+kAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
BAQEBAXkiyGdTn77iaHt79nLHa1oQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
EBAQEBAQEBAQEJA9IC+ZVvolhHS3b88hpE+130FAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQP4AMmQK7vNpruVme80OppxAQEBAQEBAQEBAQEBAQEBAQEBAQE
BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQECOCeluH1PdeBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBAQEBAQkGND4pvaQUBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBADgYJE0OG+TTh0TggICAgICAgICAgICAgICAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICB7QqqSgpS78TUBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQF5LGRF4h2MjwoICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICMhGkPI0izvTP6Ju/IosLnk/b1/yBwEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB+RVyz1+mdjDlEu6gW4wKAgICAgICAgICAgICA
gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKyB6Scc1hp76MdjCGk3I0f5jsAAQEBAQ
EBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQHZBRJ348PhYkhNrb6rWTI
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICMi2kB8yPfTRJFKe
pnz07fbjdX40tT4QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
JCtICuSqtWndjDllHotCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA
gICAjIRpDPpj797B+umSOv08PvGcj0sQUBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
BAQEBAQEBAQEBAQEBAdkD8pJppV/mkMXRYT5VuRtf3kFXU8kHAQEBAQEBAQEBAQEBAQEBAQEB
AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQF5DGQoltbbImQxzYpMkMVN7SAgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAeDnMZEype8p46CgICAgICAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIA8AeSem9pr0oKAgICAgICAgICAgIC
AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgOwJSU0zh3ynW7yvOM17ceRurAgICAgI
CAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICMi2kKr00dFTZgdTrjU7A
AE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ADIEzMA8sQMgDwxAyBPzADIEzMA8sQMgDwxAyBPzADIEzMA8sQMgLxnewD4q3POy8/Oz
Mq6vMfWt7Fla+bib8HNDIA8MQMgT8wAyBMzAPLEDIA8MQMgT8wAyBMzAPLEDIA8MQMgT8wAyB
MzAPLEDIA8MQMgT8wAyBMzAPLEDIA8MQMgT8wAyHu2B+B3mpntEb7tZuZzzsqzN4rv6MbNOW9
9GzduZi7u180MgDwxAyBPzADIEzMA8sQMgDwxAyBPzADIEzMA8sQMgDwxAyBPzADIEzMA8sQM
gDwxAyBPzADIEzMA8sQMgDwxAyBPzADIe7YHeLdzzvYI/EHF9zszLz9b3O+Wm3Mu+rRvw80Mg
DwxAyBPzADIEzMA8sQMgDwxAyBPzADIEzMA8sQMgDwxAyBPzADIEzMA8sQMgDwxAyBPzADIEz
MA8sQMgDwxAyBPzADIe7YHeMXMbI/AH3TOWVn3076rm3O+OaviujfM/B5uZgDkiRkAeWIGQJ6
YAZAnZgDkiRkAeWIGQJ6YAZAnZgDkiRkAeWIGQJ6YAZAnZgDkiRkAeWIGQJ6YAZAnZgDkiRkA
eWIGQN6cc7ZnAIArbmYA5IkZAHliBkCemAGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAHliBkCem
AGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAH
liBkCemAGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAHliBkCemAGQJ2YA5IkZAHliBkDe/wB5w4S
q9G4M2AAAAABJRU5ErkJggg==
ATTENDEE;CN=Wayne Lee;PARTSTAT=REQ-PARTICIPANT;RSVP=TRUE:mailto:song.John#
company.com
CLASS:PUBLIC
DESCRIPTION:Hello\,\n\nWe hope you enjoy your visit
DTEND:20190723T183343
DTSTAMP:20190723T153343Z
DTSTART:20190723T173343
GEO:52.051681;-4.283453
LOCATION:FranceORGANIZER;CN=Wayne Lee:mailto:wayne#digital-forge.co.uk
SEQUENCE:0
SUMMARY:Interview
TRANSP:TRANSPARENT
UID:b9fb0c3e-728c-4121-912e-9412885ebbb4
BEGIN:VALARM
ACTION:DISPLAY
SUMMARY:Alert 1 hour before
TRIGGER:-PT1H
END:VALARM
END:VEVENT
END:VCALENDAR
And then trying to send with the following code:
var ical = new TextPart("calendar")
{
ContentTransferEncoding = ContentEncoding.Default,
ContentDisposition = new ContentDisposition (ContentDisposition.Inline),
Text = calendar
};
ical.ContentType.Parameters.Add("method", "REQUEST");
message.Body = ical;
Any help would be greatly appreciated.
Thanks
The calendar invite comes through fine for me to accept/decline etc but via email, the attachment does not show.
Based on a sample meeting request that I sent to myself from Outlook, Outlook does not add a Content-Disposition to the text/calendar part.
It also base64 encodes it.
Try this:
var ical = new TextPart("calendar")
{
ContentTransferEncoding = ContentEncoding.Base64,
Text = calendar
};
ical.ContentType.Parameters.Add("method", "REQUEST");
I also noticed that Outlook tends to construct a MIME message with the following structure (which may or may not be needed):
multipart/alternative
text/plain
text/html
text/calendar
Related
Hello I have tried using mailjets api to send an excel document.
I first encode the excel file to base64 using mailjets library.
I then use mailjets library to add the file as an attachment and set the mime type application/vnd.ms-excel.
Heres an example.
request = new MailjetRequest(Emailv31.resource)
.property(Emailv31.MESSAGES, new JSONArray()
.put(new JSONObject()
.put(Emailv31.Message.FROM, new JSONObject()
.put("Email", "pilot#mailjet.com")
.put("Name", "Mailjet Pilot"))
.put(Emailv31.Message.TO, new JSONArray()
.put(new JSONObject()
.put("Email", "passenger1#mailjet.com")
.put("Name", "passenger 1")))
.put(Emailv31.Message.SUBJECT, "Your email flight plan!")
.put(Emailv31.Message.TEXTPART, "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!")
.put(Emailv31.Message.HTMLPART, "<h3>Dear passenger 1, welcome to Mailjet!</h3><br />May the delivery force be with you!")
.put(Emailv31.Message.ATTACHMENTS, new JSONArray()
.put(new JSONObject()
.put("ContentType", "application/vnd.ms-excel")
.put("Filename", "test.txt")
.put("Base64Content", "excelFileBase64")))));
response = client.post(request);
However I always receive the file as its string represented base64 encoded.
Use ContentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
and test.xlsx
I’m using python to send emails using Mailgun’s SMTP server. I wish to use Mailgun’s builtin ability to tag my messages, and to track open and click events.
I know this can be done using Mailgun’s send message API, by adding headers like o:tag, o:tracking, o:tracking-clicks and o:tracking-opens (as explained here: https://documentation.mailgun.com/en/latest/api-sending.html#sending)
However, seeing as I'm the SMTP gateway and not the API, I’m trying to understand how to achieve the same result - emails that are tagged and fully tracked in Mailgun.
Any thoughts on how it can be done?
This is my little script at the moment:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Found it!
The following X-Mailgun headers can be added:
https://documentation.mailgun.com/en/latest/user_manual.html#sending-via-smtp
So my script would be:
message = MIMEMultipart("alternative")
message["Subject"] = "This is an email"
message["From"] = “<from email>”
message["To"] = “<to email>”
message["X-Mailgun-Tag"] = "<tag>"
message["X-Mailgun-Track"] = "yes"
message["X-Mailgun-Track-Clicks"] = "yes"
message["X-Mailgun-Track-Opens"] = "yes"
htmlpart = MIMEText("<html><body>email here!</body></html>", "html")
message.attach(htmlpart)
server = smtplib.SMTP_SSL(“<smtp server>”, 465)
server.ehlo()
server.login(“<username>”, “<password>”)
server.sendmail(from_addr=“<from email>”, to_addrs=“<to email>”, msg=message.as_string())
server.close()
Now my email is tagged (can be analysed on a tag level in Mailgun), and clicks are tracked.
Happy days!
I'm trying to send an attachment through flask-mail. The email is sent, the attachment is also present in the email but I cannot open the attached file.
Gmail shows a message Couldn't Load Image when i click on the image attachment.
This is my code :
msg = Message('You have a new Message', sender = 'noreply#gmail.com',
recipients = ['user#gmail.com'])
msg.body = f'''Details are -
Name : {form.name.data}
Email : {form.email.data}
Phone : {form.phone.data}
Template : {form.template.data}
Message : {form.message.data}
'''
msg.attach(
form.details.data.filename,
'application/octect-stream',
form.details.data.read())
mail.send(msg)
Where am I wrong ?
I'm trying to send emails using Serilog.Sinks.Email NuGet package (v1.5.0.0) with the Mandrill SMTP service. The following code executes but does not send any emails. When I try and use the same credentials using the System.Net.Mail.SmtpClient, it works and send an email.
EmailConnectionInfo info = new EmailConnectionInfo()
{
EmailSubject = "Email subject",
FromEmail = "from#gmail.com",
MailServer = "smtp.mandrillapp.com",
NetworkCredentials = new NetworkCredential("mandrill_username", "mandrill_apikey"),
Port = 587,
ToEmail = "to#gmail.com"
};
Log.Logger = new LoggerConfiguration()
.WriteTo.Email(info)
.CreateLogger();
Log.Error("Houston we have a problem");
As you spotted, this was a bug in the latest build of the Email sink, which your graciously-provided pull request has fixed. Version 1.5.13 of the sink, now on NuGet, includes the fix.
I would like to send an encrypted EMail Message with Exchange WEb Services using C#.
Is there any possibillity?
Thanks
Edit:
My Mail body encrypter:
public static byte[] encry(string body, ContentTyp typ, string to )
{
X509Certificate2 cert = GetMailCertificate(to);
StringBuilder msg = new StringBuilder();
msg.AppendLine(string.Format("Content-Type: text/{0}; charset=\"iso-8859-1\"", typ.ToString()));
msg.AppendLine("Content-Transfer-Encoding: 7bit");
msg.AppendLine();
msg.AppendLine(body);
EnvelopedCms envelope = new EnvelopedCms(new ContentInfo(Encoding.UTF8.GetBytes(msg.ToString())));
CmsRecipient recipient = new CmsRecipient(SubjectIdentifierType.IssuerAndSerialNumber, cert);
envelope.Encrypt(recipient);
//System.IO.MemoryStream ms = new System.IO.MemoryStream(envelope.Encode());
return envelope.Encode();
}
Main
byte [] con = encrypted.encry("test", encrypted.ContentTyp.plain, "test#server.com");
EmailMessage msg1 = new EmailMessage(_server);
msg1.MimeContent = new MimeContent("UTF-8", con);
msg1.ToRecipients.Add("user#server.com");
msg1.InternetMessageHeaders = ??
msg1.Send();
If you are referring to S/Mime encryption, then you'll have to create the encrypted message according to RFC 3852 and RFC 4134. After you've done that, you can send the message.
Using the EWS Managed API, this can be done as follows:
var item = new EmailMessage(service);
item.MimeContent = new MimeContent(Encoding.ASCII.HeaderName, content);
// Set recipient infos, etc.
item.Send();
EDIT:
You should add the standard headers like From, To, Date, Subject, etc. And the content-type.
Subject: Test
From: "sender" <sender#yourcompany.com>
To: "recipient" <recipient#othercompany.com>
Content-Type: application/pkcs7-mime; smime-type=signed-data; name=smime.p7m
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=smime.p7m
Your encrypted body goes here
Just use a StringWriter put all that together. The result is your MIME body.