Print a mail from EWS in vb.net - vb.net

In my vb .net program I select an email from my Exchange server as a message in Exchange Web Services.
I am looking for a solution to print that message to a network printer. Can anyone help?
Either print directly as an email from EWS or as a file.
For Each i As Item In emailitems
' search and find an email
i.Load(New PropertySet(ItemSchema.MimeContent))
Dim mc As New MimeContent
Dim fs As New FileStream("c:\temp\mail.eml", FileMode.Create)
mc = i.MimeContent
fs.Write(mc.Content, 0, mc.Content.Length)
fs.Close()
fs = Nothing
' how do I print message i or mail.eml to a network printer?
Next

Related

vb.ne send email from a shared mailbox

i'm supposed to send an email as customer care from a shared mailbox to several addresses of my company customers.
i'm using mailkit library and i use this code
Code:
Dim contenutomail As New MimeKit.BodyBuilder
Dim smtpclient As New MailKit.Net.Smtp.SmtpClient
Dim mail As New MimeKit.MimeMessage
smtpclient.Connect("smtp.office365.com", 587, MailKit.Security.SecureSocketOptions.StartTls)
smtpclient.Authenticate("eurostar_italia#mycompany.com", "Aprile22")
mail.From.Add(New MimeKit.MailboxAddress("", "customeroffice#mycompany.com"))
For i = 0 To mailinglist.Count - 1
mail.Bcc.Add((New MimeKit.MailboxAddress("",mailinglist(i).ToString)))
Next
contenutomail.TextBody = ""
contenutomail.HtmlBody = "hello world"
mail.Body = contenutomail.ToMessageBody
smtpclient.Send(mail)
smtpclient.Disconnect(True)
the problem is : sent mail are save in MY personal account SENT mailbox instead of shared SENT mailbox.
I don't have any Admin right to modify the office365 sharedmailbox.
can anyone help me ? i don't want to save a copy,i want the mail sent to be saved in the sent shared mailbox
i can't solve it
thanks
fabio

How to automatically classify the Outlook email sensitivity for Azure Information Protection in VB.Net?

I'm developing a windows from using vb.net, trying to send an email through outlook. My code is running fine, but once it reaches the send() line, a pop-up of Azure Information Protection to select the email sensitivity (Public, Confidential, ...etc), so the email will not be sent until a user select.
I tried ( OutlookMessage.Sensitivity = outlook.OlSensitivity.olNormal )
but still, need some one to select the classification from the Azure pop-up, full code shown below...
Dim OutlookMessage As outlook.MailItem
Dim AppOutlook As New outlook.Application
Try
OutlookMessage = AppOutlook.CreateItem(outlook.OlItemType.olMailItem)
Dim Recipents As outlook.Recipients = OutlookMessage.Recipients Recipents.Add("myemail#hotmail.com")
OutlookMessage.Subject = "Sending through Outlook"
OutlookMessage.Body = "Testing outlook Mail"
OutlookMessage.BodyFormat = outlook.OlBodyFormat.olFormatHTML
OutlookMessage.Sensitivity = outlook.OlSensitivity.olNormal
OutlookMessage.Send()
Catch ex As Exception
MessageBox.Show("Mail could not be sent") 'if you dont want this message, simply delete this line
Finally
OutlookMessage = Nothing
AppOutlook = Nothing
End Try
Hoping that the code runs using a service account, do the below
Add the above service account inside the scoped AIP policy
Set a default label in the scoped policy
Doing this will not trigger the popup as a default label is already applied (I hope).
Note: You can set different default labels for Outlook and other MS apps using AIp Policy's advanced settings

Outlook and Office 365 does not show sent items where mails were sent using a external software which is developed using vb.net

We have a mail-id in our own domain.
We configure it in outlook along with office 365.
We have using a software for our business purpose which is developed using vb.net.
Using this software, we are sending mails to our customers from the mail-id of our own (For Example user#mydomain.in).
Customers also receive the mail properly.
The problem is that we can't able to see the sent mails in our "sent items" of both outlook and office365.
Sent items does not sync.
Dim mailbody As String = ""
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("user#mydomain.in", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.office365.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("user#mydomain.in")
Dim attachment As System.Net.Mail.Attachment
e_mail.To.Add(New_Enquiry.MAIL_ID.Text)
e_mail.Subject = "Thankyou for your Enquiry"
e_mail.IsBodyHtml = True
Smtp_Server.Send(e_mail)
These are the code which I have used in vb.net.
It works properly but unable to see the sent mails in sent items.
I had used the same code for gmail also and Gmail shows the sent mails in sent items.
Kindly spot me the error.
Gmail is special: anything you send through their SMTP server will show up in your Sent folder. This is not standard behaviour: if you want messages to show up in your Sent folder, you have to PLACE them there, generally using IMAP and the APPEND command. If you have the right access, you may be able to make some sort of server side script to do this for you, but it is not the default.

WebClient.UploadData "The underlying connection was closed"

I'm trying to upload a file from an FTP site to Basecamp using the Basecamp API. I'm using a simple console application. Here's my code:
Try
Dim accountID As String = ConfigurationManager.AppSettings("BaseCampID")
Dim projectID As Integer = 9999999
Dim folderName As String = "XXXXX/XXXXX"
Dim fileName As String = "XXX.zip"
'The URL to access the attachment method of the API
Dim apiURL = String.Format("https://basecamp.com/{0}/api/v1/projects/{1}/attachments.json", accountID, projectID)
'Get the file from the FTP server as a byte array
Dim fileBytes As Byte() = GetFileBytes(String.Format("{0}\\{1}", folderName, fileName))
'Initialize the WebClient object
Dim client As New WebClient()
client.Headers.Add("Content-Type", "application/zip")
'Need to provide a user-agent with a URL or email address
client.Headers.Add("User-Agent", "Basecamp Upload (email#email.com)")
'Keep the connection alive so it doesn't close
client.Headers.Add("Keep-Alive", "true")
'Provide the Basecamp credentials
client.Credentials = New NetworkCredential("username", "password")
'Upload the file as a byte array to the API, and get the response
Dim responseStr As Byte() = client.UploadData(apiURL, "POST", fileBytes)
'Convert the JSON response to a BaseCampAttachment object
Dim attachment As BaseCampAttachment
attachment = JSonHelper.FromJSon(Of BaseCampAttachment)(Encoding.Default.GetString(responseStr))
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
Console.ReadLine()
End Try
But whenever it calls client.UploadData, I get the error message "The underlying connection was closed: The connection was closed unexpectedly." I ran into this issue earlier and thought I solved it by adding the "Keep-Alive" header, but it's not working anymore. The API works if I upload a local file with client.UploadFile, but I'd like to just upload the file from they byte array from the FTP rather than downloading the file locally then uploading it to Basecamp.
Any thoughts would be greatly appreciated. Thanks!
I never figured out what was wrong with the WebClient call, but I ended up using a Basecamp API wrapper from https://basecampwrapper.codeplex.com. That wrapper uses HTTPRequest and HTTPResponse instead of WebClient.UploadData. It's also much easier to just use that wrapper than to try writing my own code from scratch.

Email Function in VB

I need a simple email function that just sends an email (not looking to spam anyone I promise!).
Anyone, anyone? Using VB 2008
Use the SmtpClient class to do this. There's an example of sending an email asynchronously on the documentation page, but here's a basic way of doing it:
Dim client As New SmtpClient("mail.myisp.com")
Dim fromAddr As New MailAddress("jane#contoso.com")
Dim toAddr As New MailAddress("ben#contoso.com")
Dim message As New MailMessage(fromAddr, toAddr)
message.Body = "This is a test e-mail message sent by an application. "
message.Subject = "test message 1"
client.Send(message)