Sending ICS Calendar File by Email Vb.net - vb.net

When I send a calendar file by email, it appears correctly on recipient's email. When I send same file programmatically, it does not. here is what I do programmatically
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Mail As New MailMessage
Mail.Subject = "test email"
Mail.To.Add("someuser#gmail.com")
'Mail.To.Add("somesender#gmail.com")
Mail.From = New MailAddress("somesender#gmail.com")
Mail.Body = "This is a sample email using VB.NET"
Dim attachment As System.Net.Mail.Attachment
attachment = New System.Net.Mail.Attachment("C:\Users\x\Downloads\testCalendar.ics")
Mail.Attachments.Add(attachment)
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
'SMTP.DeliveryMethod = SMTP.DeliveryMethod.SpecifiedPickupDirectory
SMTP.Credentials = New System.Net.NetworkCredential("somesender#gmail.com", "password")
SMTP.Port = "587"
SMTP.Send(Mail)
End Sub
here is the content of the test ics file
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART:20160930T110000
DTEND:20160930T120000
SUMMARY:Bastille Day Party
LOCATION:123 Main Street, Anahiem CA
DESCRIPTION:THIS IS A TEST DESCRIPTION
END:VEVENT
END:VCALENDAR
Any ideas?
thanks

There is absolutely no way to do this using System.Net.Mail as the resulting MIME message content will have the wrong structure. The VCalendar information needs to be contained within a specific MIME part but it will be placed in a separate one and treated as a normal attachment.
I wrote my own SMTP client and MIME message generator specifically to overcome this issue by creating the MIME content exactly as is required. The issue with doing this was that I needed to cater for different security protocols, such as NTLM, which was a pain to code.
You may be able to find a third-party SMTP client that supports the behaviour you require in the nuget gallery.

Related

Send newsletter HTML Email with pictures as body

I'm new to this group and i have one question. how can i attach pictures on the HTML newsletter that i have. when i send the newsletter everything goes well but the pictures are not showing on the email. please help. this is the code.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Body As String = GetWebPageContent(Sender_email, Message)
Dim Mail As New MailMessage
Mail.Subject = "Test HTML"
Mail.To.Add(to_email)
Mail.From = New MailAddress(Sender_email)
Mail.Body = Body
Mail.IsBodyHtml = True
Mail.Priority = MailPriority.Normal
Dim SMTP As New SmtpClient(SMTP_Confg)
SMTP.EnableSsl = False
SMTP.Credentials = New System.Net.NetworkCredential(Sender_email, Password)
SMTP.Port = Port_Num
Try
SMTP.Send(Mail)
MsgBox("Successfully Sent!!!")
Catch ex As Exception
MessageBox.Show(" - your confermation email is not sent! " & vbNewLine & " Please contact your Administrator!")
End Try
End Sub
Private Function GetWebPageContent(ByVal recipient As String, ByVal customMsg As String) As String
Dim objStreamReader As New StreamReader("C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML")
'read html template file'
Dim bodyMsg As String = objStreamReader.ReadToEnd()
Return bodyMsg
End Function
It looks like you're copying the raw HTML from this file:
"C:\Users\alex.GFH\Desktop\Email\beefree-s09uuvnlono.HTML"
As the message body of your email.
My psychic powers tell me that you've got <img> tags inside your HTML that are pointing to relative locations. e.g. <img src="picture.jpg"/>. As such when the HTML email is opened in someone else's browser or mail app, the renderer has no idea where to fetch "picture.jpg" from.
And even if it did have the full URL, most mail apps won't fetch URL images by default until the user acknowledges the privacy risk.
I think if you want your images to just show up when the mail is opened, inline the image bytes directly into the <img> tag. You base 64-encode the image and stick on a header (e.g. data:image/png;base64, or data:image/jpeg;base64,. That becomes the src attribute.
E.g:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />
More details here: https://www.rfc-editor.org/rfc/rfc2397

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.

Click the Link to Approve the Request Form

I'm writing an approval system. In the approval system requester need to request to approve the request application. After the requester fill up the information and send the application to manager via email. The manager just need to click the link to view the application and approve the application. Now, I'm stuck to do the code for click the link for approve. Anyone Please give suggestion or code to continue my project. Thank you.
Dim mail As New MailMessage()
mail.[To].Add(AppMgr.SelectedValue)
'mail.To.Add("man#celestica.com")
mail.IsBodyHtml = True
Dim smtp As New SmtpClient()
smtp.Host = "smtp.gmail.com"
'Or Your SMTP Server Address
smtp.Credentials = New System.Net.NetworkCredential("YourGmailID#celestica.com", "YourcelesticamailPassword")
'Or your Smtp Email ID and Password
smtp.EnableSsl = True
smtp.Send(mail)
Above is the code about send email to manager. Please help.

Email Function will not work properly in Visual Studios

I am trying to generate an email function where it sends the user an email, however for some reason it is just not working properly and it does not give any error messages.
It just brings up a message box stating that "There is a problem at this time. Please try again later". This is message box which appears when the email fails to be sent, however could you please help to resolve by issue.
Error Message says
It says that 'sends the email. SMTP.Send(email)- An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at –
Please view the code below.
imports System.Net.Mail
Public Class EmailF
'assigns a new message to the email
Dim email As New MailMessage
'smtp is the server that has been used to send the email
Dim smtp As New SmtpClient
'assigns a new email address
Dim mail As System.Net.Mail.MailAddress
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'selects which email address to send the email from...
email.From = New MailAddress("blood4all.business#gmail.com")
email.Subject = SubBox.Text
email.Body = MessBox.Text
email.To.Add(ToBox.Text)
'the smtp outlook host.
Dim SMTP As New SmtpClient("smtp.gmail.com")
'the smtp port.
SMTP.Port = 587
SMTP.EnableSsl = True
'the login details for the gmail account.
SMTP.Credentials = New System.Net.NetworkCredential("blood4all.business#gmail.com", "Blood123")
'starts the progress bar.
Timer1.Start()
ProgressB.Show()
'sends the email.
SMTP.Send(email)
'pop up box conirms that the email has been sent.
MsgBox("The e-mail has been sent!")
Catch ex As Exception
MsgBox("There is a problem at this time. Please try again later")
ProgressB.Hide()
End Try
End Sub
The exception message is :
An unhandled exception of type 'System.Net.Mail.SmtpException' occurred in System.dll Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at ...
The credentials you pass are used only if you set the UseDefaultCredentials property to false before you set the new credentials. Otherwise your Windows credentials will be used.
Changing the value of this property clears the Credentials property, which is why you need to set it before passing the new credentials:
SMTP.UseDefaultCredentials = False
SMTP.Credentials = New System.Net.NetworkCredential("blood4all.business#gmail.com", "Blood123")
EDIT
You'll also have to "allow less secure applications" from your GMail account settings, as described in this SO question and the GMail support site. Normally, GMail requires applications to use either an application key.
SMTP (the protocol) doesn't have this functionality so you need to modify your account settings to allow connecting without an application key
I have now got this working as I created a new gmail account, maybe my all gmail account consisted of network and security issues which has now been amended. Thank for help and much appreciated.

Send email from VB.Net without SMTP Gateway

I am looking for an alternative to using smtp.gmail.com as they have disabled SMTP relay at my work place. And they are adamant they will not make any exceptions.
I have written an extensive application in VB.net which captures a boat load of requirements from the user. At the end there is obviously a button to send all the captured data to some recipients. My code is as follows :
Private Sub btnEmail_Click(sender As Object, e As EventArgs) Handles btnEmail.Click
email.From = New MailAddress("kuldip.mond123#gmail.com", "Kuldip Mond")
email.Subject = "SAP Order Prerequisite Form"
email.Body = "Message Text as Body of email."
email.IsBodyHtml = True
email.To.Add("kmond#mycompany.com")
smtp.EnableSsl = True
smtp.Port = 587
smtp.Host = "smtp.gmail.com"
smtp.UseDefaultCredentials = False
smtp.Credentials = New Net.NetworkCredential("kmond#mycompany.com", "*********")
smtp.Send(email)
MsgBox("Email Sent")
End Sub
I have considered and read up on SMTP Client with gmail Apps script etc but somewhere sometime sooner or later they all boil down to using a smtp.gmail.com
Would appreciate any guidence.
Thanks in advance.
Will an SMTP gateway be available when the application is published? If so, there are a number of local SMTP host solutions for development environments.
I am in the same situation with my IT team myself (no SMTP for dev, but we have access for UAT and Live), and I use the SMTP4Dev (https://smtp4dev.codeplex.com/) application happily.
If you point to the application as your SMTP server, any e-mails sent out using it will be caught by the application and be readable by you.