Hide sender's address in email - vb.net

I am working on visual studio 2012 vb.net coding. I was asked to create an application to my company that sends emails to clients but they want to display company's name at client's screen and the email address should be hidden. My code is working properly except this point(hiding sender address) and I am using smtp client.
Any hints?
Below is my code :
Dim mail As New MailMessage()
'mail.From = New MailAddress("Me#domain.com", "Me")
mail.From = New MailAddress("""Me "" <Me#domain.com>")
mail.[To].Add("somebody#domain.com")
mail.Subject = "Test email from App"
mail.Body = "Dear somebody, this email was sent from our project as a test email, Regards."
Dim smtp As New SmtpClient("localhost")
Try
nsmtp.Send(mail)
Response.Write("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
Response.Write("Send failure: " & exc.ToString())
End Try

Related

SmtpClient MailMessage ignoring Server Mail Flow Rule

I have an Simple Application that Sends and email as Follows:
Private Sub sendEmail()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(cmbFrom.Selected.Value)
mail.[To].Add(cmbTo.Selected.Value)
mail.IsBodyHtml = True
'set the content
mail.Subject = getSubject()
mail.Body = getBody()
If cmbSubj.Selected.Description = "Confirmation" Then
mail.Headers.Add("Disposition-Notification-To", cmbFrom.Selected.Value)
End If
'set the server
Dim smtp As New SmtpClient("Mail.MyDomain.Co.Uk")
'smtp.UseDefaultCredentials = True
smtp.Credentials = CredentialCache.DefaultNetworkCredentials
'send the message
Try
smtp.Send(mail)
Application.SBO_Application.MessageBox("Your Email has been sent sucessfully - Thank You")
oForm.Close()
Catch exc As Exception
Application.SBO_Application.MessageBox("Send failure: " & exc.ToString())
End Try
End Sub
and this Exchange Server Mail Flow Rule:
Unfortunately the mail flow rule is not applying to messages,
How can i ensure this Mail Flow rule applies to the App based Emails and why Has it been ignored so far?
Changing the Mail Flow Rule Resolved the issue, However the question of why the rules were missed when using the smtpClient Remains.
To resolve the rule was changed to "The Sender Address Matches..." and the Domain name.
mail flow rule 2

VB: How to send email with SMTP... Dynamically set host and port for major ISP's

I am working on a VB application that sends an HTML email. I found this, and am trying to implement it.
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(EmailFrom, "Display Name")
mail.To.Add(EmailTo)
'set the content
mail.Subject = "Subject Line"
mail.Body = "Message body"
mail.IsBodyHtml = True
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
I don't have any info on the argument passed to SmtpClient() for this code snippet.
I have found videos showing how to connect to google smtp using "smtp.gmail.com" and a specific port. However, This would only be practical if all of the users of my application will have Gmail. I don't want to force them to have one in order to have access to the functionality.
Could any of you experts provide me with some help on dynamically selecting the correct smtp server and port based on their email?
for example, email is stored in a variable called email:
Dim email As String = "me#gmail.com"
This email is coming from MySql database so how do I take variable string and check which ISP they use and then have my code use the correct smtp and port for that ISP?
Also, I've read that now days authentication is required so I will likely prompt user with input box before calling procedure that sends the email.
Here's some code showing that:
Hotmail:
Smtp.live.com
Port: 587
Gmail:
smtp.gmail.com
Port: 587
Yahoo:
smtp.mail.yahoo.com
Port: 465
Aol:
smtp.aol.co.uk
Port: 587
imports system.net.mail
dim Mail as new mailmessage
Try
mail.From = New MailAddress("FROM EMAIL")
mail.To.Add(TO EMAIL)
mail.Subject = "SUBJECT"
mail.Body = "BODY"
Dim s As New SmtpClient("HOST")
s.Port = PORT
s.EnableSsl = True
s.Credentials = New System.Net.NetworkCredential("FROM EMAIL, "FROM PASSWORD")
s.Send(Mail)
MsgBox("E-mail was sucsessfully sent!", MsgBoxStyle.Information, "Information")
Catch ex As Exception
End Try
I'm completely stumped. Any help would be greatly appreciated. I am also open to any ideas that accomplish same feat even if not in accordance with first code snippet. Thanks in advance.

vb.NET SmtpClient not able to send email using email

I'm trying to run this a block of code that exports the file I am working on to a PDF and emailing it to a 'client' using gmail.
I keep getting the message "Failure Sending Message", if you could help shed some light on this that would be appreciated.
I also purposely "*****" my emails credentials for obvious reasons.
<MiCode(ControlScriptEventType.AfterInkAdded, "Email")> _
Public Sub Ctl_Email_AfterInkAdded(ByVal e As AfterInkAddedEventArgs)
MsgBox("1")
Dim EmailTo As String = _EmailAddress.Value
Dim EmailToName As String = "Client"
Dim EmailFrom As String = "******"
Dim EmailFromName As String = "WHSD"
Dim fileName As String = String.Empty
Dim erl As New System.Collections.Generic.List(Of ExportResult)
For Each er As ExportResult In _form.Validator.ExportResults
erl.Add(er)
fileName = System.IO.Path.GetFileNameWithoutExtension(er.ExpandedFilePath)
Next
Try
Dim fromAddress As New MailAddress(EmailFrom, EmailFromName)
Dim toAddress As New MailAddress(EmailTo, EmailToName)
Using msg As New MailMessage(fromAddress, toAddress)
msg.Body = "This will be the body of the message you are sending." & VbCrLf & "Thank you for your purchase."
msg.Subject = (Me._form.Name & " (" & fileName & ")")
' Add the mail body - an HTML file attached to this form.
For Each attData As AttachmentData In _form.Attachments
If String.Compare(attData.Name, "Lead Generation.html") = 0 Then
msg.Body = System.Text.UTF8Encoding.UTF8.GetChars(attData.BinaryData())
msg.Body = msg.Body.Replace("[filename]", fileName)
End If
Next
' Add pdf/csv file attachments to mail - they are datapaths of the form.
For Each er As ExportResult In erl
If er.Success And ( er.DataPathName = "PDF" Or er.DataPathName = "CSV" ) Then
msg.Attachments.Add(New Attachment(er.ExpandedFilePath))
End If
Next
Dim client As New SmtpClient("aspmx.l.google.com", 25)
'client.EnableSsl = True
'client.Timeout = 10000
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.UseDefaultCredentials = False
client.Credentials = New NetworkCredential("********", "******")
client.Send(msg)
Me.RecordExportResult("Email", True, "Sent email", "Sent email to " & EmailToName & "(" & EmailTo & ")", "")
MsgBox("Sent!")
End Using
Catch ex As Exception
Me.RecordExportResult("Email", False, ex.Message, ex.Message, ex.Message)
MsgBox(ex.Message)
End Try
End Sub
Looks like you are trying to use gmail as your mail server in which case you will definately need to use SSL/TLS and make sure your credentials are as follows;
Google's SMTP server requires authentication, so here's how to set it up:
SMTP server (i.e., outgoing mail): smtp.gmail.com
SMTP username: Your
full Gmail or Google Apps email address (e.g. example#gmail.com or
example#yourdomain.com)
SMTP password: Your Gmail or Google Apps
email password
SMTP port: 465
SMTP TLS/SSL required: yes
In order to store a copy of outgoing emails in your Gmail or Google Apps Sent folder, log into your Gmail or Google Apps email Settings and:
Click on the Forwarding/IMAP tab and scroll down to the IMAP Access section: IMAP must be enabled in order for emails to be properly copied to your sent folder.
NOTE: Google automatically rewrites the From line of any email you send via its SMTP server to the default Send mail as email address in your Gmail or Google Apps email account Settings. You need to be aware of this nuance because it affects the presentation of your email, from the point of view of the recepient, and it may also affect the Reply-To setting of some programs.
Workaround: In your Google email Settings, go to the Accounts tab/section and make "default" an account other than your Gmail/Google Apps account. This will cause Google's SMTP server to re-write the From field with whatever address you enabled as the default Send mail as address.

Send email from windows app using vb.net

i have the following code,i'm trying to send an email from my windows application but it's not working... any help ? note that i'm using vb.net and i'm not getting any errors.. i'm just not receiving any emails !
Private Sub senemail()
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("jocelyne_elkhoury#inmobiles.net")
mail.To.Add("jocelyne_el_khoury#hotmail.co.uk")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
End Sub
In my experience, sending email via .net (and vb6 before it) is weird. Sometimes it should work and just doesn't, sometimes because of .net bugs and sometimes incompatibility with the smtp server. Here is some code that works on VB 2008, and it should work with 2010.
Using msg As New MailMessage(New MailAddress(fromAddress, fromName), New MailAddress(toAddress))
Try
Dim mailer As New SmtpClient
msg.BodyEncoding = System.Text.Encoding.Default
msg.Subject = subject
msg.Body = body
msg.IsBodyHtml = False
mailer.Host = mailserver
mailer.Credentials = New System.Net.NetworkCredential(username, password) ' may or may not be necessary, depending on the server
mailer.Send(msg)
Catch ex As Exception
Return ex.Message
End Try
End Using ' mailmsg
If this doesn't work, try using localhost instead of 127.0.0.1 for the mailserver.
If that doesn't work, try using your system name (the one that shows up on the network) for the mailserver.
If that doesn't work, try using an external smtp server with your own username and password (just for testing).
profit.

vb.net send email

I was wondering how I could send an email from within a vb application? Can any one assist in where to begin?
Use the SmtpClient class within the System.Net.Mail namespace
Example.
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("xx#xx")
mail.[To].Add("xx#xx")
'set the content
mail.Subject = "This is an email"
mail.Body = "this is a sample body"
'set the server
Dim smtp As New SmtpClient("localhost")
'send the message
Try
smtp.Send(mail)
Response.Write("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
Response.Write("Send failure: " & exc.ToString())
End Try
You can use the System.Net.Mail namespace, look it up and see if it helps. I use C# but I imagine it is similar, create a client, then a message, set params of the message and then client.Send() will send the message.