I am sending email using smtp client from office 365 account . below is the code that i am using to send the email. The email is going to the JUNk folder in outlook and also the From address is showing as EmployeeName# <yyy.com noreply#xxx.com> instead of EmployeeName#yyy.com <noreply#xxx.com>. So can any one please give me any solution to fix this issue
Dim client As New SmtpClient()
Dim message As New MailMessage()
Dim par_ReplyName As String = "noreply#xxx.com"
Dim par_ReplyAddress As String = "EmployeeName#yyy.com"
message.From = New MailAddress(par_ReplyName, par_ReplyAddress)
message.ReplyToList.Add(par_ReplyAddress)
message.Priority = MailPriority.Normal
message.Subject = "Test Email"
message.Body = "some HTML content"
message.IsBodyHtml = True
client.Host = "smtp.office365.com"
client.Port = 587
client.Credentials = New System.Net.NetworkCredential(smtpUser, smtpPassword)
client.EnableSsl = True
client.Send(message)
Here's how you're using the MailAddress constructor:
message.From = New MailAddress(par_ReplyName, par_ReplyAddress)
Here's the declaration for that constructor from the documentation:
'Declaration
Public Sub New ( _
address As String, _
displayName As String _
)
Do you see anything amiss there, like maybe you have the arguments the wrong way around?
Related
I want to sending email through smtp.office365.com in VB.NET
It work!! when i use "FROM" address same as user authentication
BUT how to send emails using other email address as the FROM address in domain
I try "Mailbox Delegation" set other email address for behalf
BUT it don't work. Please suggest where I'm going wrong.
I am using the following to
Dim myMessage As New System.Net.Mail.MailMessage
Dim myClient As New System.Net.Mail.SmtpClient()
Dim strUserName As String = "john#domain.com"
Dim strPassword As String = "p#ssw0rd"
myClient.Port = 587
myClient.Host = "smtp.office356.com"
myClient.Credentials = New System.Net.NetworkCredential(strUserName, strPassword)
myClient.EnableSsl = True
myMessage.From = New System.Net.Mail.MailAddress("marry#domain.com")
myMessage.To.Add(strTo)
myMessage.Subject = "Send E-mail using Office365"
myMessage.Body = "Test Send Email"
myClient.Send(myMessage)
I have a mail function 'Sendmail' in my VB app, as so...
Public Function Sendmail(ByVal mailrecipient As String, ByVal mailsubject As String, ByVal mailbody As String)
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
SmtpServer.Credentials = New _
Net.NetworkCredential(internal_mail_server_username, internal_mail_server_password)
SmtpServer.Port = 25
SmtpServer.Host = internal_mail_server
mail = New MailMessage()
mail.From = New MailAddress(internal_email_sender)
mail.To.Add(mailrecipient)
mail.Subject = mailsubject
mail.IsBodyHtml = True
mail.Body = mailbody
SmtpServer.Send(mail)
MessageBox.Show("Mail successfully sent to " & mailrecipient)
Return "Success"
Catch ex As Exception
End Try
End If
End Function
This works great, passing the recipient, subject and body to it sends HTML mail out... fantastic.
What I need to is include with that email a plain text version with the mail that goes out.
Is there a simple way I can achieve this?
Use alterativeViews
'first create the Plain Text part
Dim plainView As AlternateView = AlternateView.CreateAlternateViewFromString(Plain_Text)
'then create the Html part
Dim htmlView As AlternateView = AlternateView.CreateAlternateViewFromString(HTML_Text)
mail.AlternateViews.Add(plainView)
mail.AlternateViews.Add(htmlView)
Obviously you need to pass both the PLain_Text and HTML_Text as parameters to the routine.
I wanna send an Email from my Webservice, written in vb.net, but I get an Timeout.
What is wrong?
Dim toaddress As MailAddress = New MailAddress("xxx")
Dim fromaddress As MailAddress = New MailAddress("yyy")
' The structure for MailMessage(from, to)
Dim message As MailMessage = New MailMessage(fromaddress, toaddress)
message.Subject = "I have sent you a message from a program!"
message.Body = "Hello World!"
Dim messanger As SmtpClient = New SmtpClient("smtpxxx", 995)
messanger.Credentials = New NetworkCredential("user", "password")
messanger.EnableSsl = True
messanger.Send(message)
You are doing many things wrong and some of the information you have given are not clear enough. host name and port names have to give properly. it chooses which mail service you are using, from your code it is not correctly provided, so i will give a snippet that uses gmail to send mail. please go through this and make changes as per your SmtpHost.
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
This link help you to find the smtp.Server and Port numbers, you can use this thread for check the limitations of smtp.servers
I am trying to make a simple e-mail sending program but it has confused me when it said object reference not set to an instance of an object
Try
Dim mail As MailMessage
Dim client As SmtpClient
Dim SmtpServer As New SmtpClient()
Dim fromAddress As String
Dim toAddress1 As String
Dim toAddress2 As String
Dim toAddress3 As String
Dim subject As String
Dim message As String
SmtpServer.Credentials = New Net.NetworkCredential("*********#gmail.com", "**********")
client.UseDefaultCredentials = False
fromAddress = FromEmail.Text
If ToEmail1.Visible = True Then
toAddress1 = ToEmail1.Text
ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True Then
toAddress1 = ToEmail1.Text
toAddress2 = ToEmail2.Text
ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True And ToEmail3.Visible = True Then
toAddress1 = ToEmail1.Text
toAddress2 = ToEmail2.Text
toAddress3 = ToEmail3.Text
End If
subject = "Subject"
Message = "Message"
mail = New MailMessage(fromAddress, toAddress1, subject, Message)
client = New SmtpClient("Smtp.live.com")
client.Port = 587
Dim SMTPUserInfo As New System.Net.NetworkCredential("user#hotmail.com", "password")
client.Credentials = SMTPUserInfo
client.Send(mail)
MsgBox("sent")
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
you're declaring two smtpclients
Dim client As SmtpClient
Dim SmtpServer As New SmtpClient()
you instantiated SmtpServer, but not client. Then you do
client.UseDefaultCredentials = False
I guess this is where the exception is raised.
the code looks like having some lines to send some mail through SmtpServer from a google account and other lines to send some mail through client from a hotmail account. Besides, SmtpServer is using some server defined in config.sys.
I have two pages the first one will receive all data that are required from the user such as username e.mail and then the same page will do the calculation but when clicking on result button two things should happen: 1-the result and all user inputs should be sent to the second page 2- the same information should be sent to the user email as the e.mail messege
I wrote the e.mail code but I dont know how do put the results as message
Help please
This code worked for me
Try
Dim mail As MailMessage
Dim client As SmtpClient
Dim fromAddress As String
Dim toAddress As String
Dim subject As String
Dim message As String
fromAddress = "user#hotmail.com"
toAddress = "user#hotmail.com"
subject = "Radiation"
message = "mail sent"
mail = New MailMessage(fromAddress, toAddress, subject, message)
client = New SmtpClient("Smtp.live.com")
client.Port = 587
client.EnableSsl = True
client.UseDefaultCredentials = False
Dim SMTPUserInfo As New System.Net.NetworkCredential("user#hotmail.com", "password")
client.Credentials = SMTPUserInfo
client.Send(mail)
Label1.Text = "sent"
Catch ex As Exception
Label1.Text = ex.Message.ToString()
End Try