CDO.Message To and From Fields Changed to "Friendly Name" and Email Address - asp-classic

When I first created this Classic ASP script, with the help of W3Schools, to send email, it worked fine. Now I'm having issues with sending the actual email; it appears to hang on the .Send method.
I noticed that when I set the To and From email address to just the email address, it reformats it to a "Friendly Name"/Email Address format:
myMail.From="Support#myDomain.com"
Response.Write myMail.From
The output of the Response Write is:
"Support#myDomain.com" <Support#myDomain.com>
I don't know if this was happening before, or if I should be setting the To and From fields in this format. Just to check if this is causing my problem, is there anyway to prevent these fields from being changed from just the email address?

Maybe the e-mail sending from the server now needs some kind of authentication such as setting these fields:
' Outgoing SMTP server.
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mydomain.com"
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDO.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
' Type of authentication, 0=NONE, 1-Basic (Base64 encoded), and 2=NTLM.
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
' UserID on the SMTP server
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "support#mydomain.com"
' Password on the SMTP server
objCDO.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "myemailpassword"
' Update config.
objCDO.Configuration.Fields.Update

The issue stemmed from the fact that the "From" email address was actually a distribution list and the account credentials used to login to the email server were not authorized to "Send As". Once that was rectified emails sent without further problems.
Thanks for the response.

Related

The server response was: 5.7.57 SMTP - Office 365

Currently we have a web form that send's emails which has stopped working months back with the migration of Office 365 at our company. I have eliminated all other code while troubleshooting and just run email portion to get the following error : "System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM ".
I have found many solutions on the web/stack overflow with the same error code, tried changing the code to proposed solutions and have had no luck.
Tried many different email aliases that are listed in our global address list with no luck for my account, different ports(25,587), different smtp addresses, and have had no luck so far.
Multiple users are stating "This code unfortunately is no longer valid with Office 365. Error message that comes up is The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [HE1PR05CA0133.eurprd05.prod.outlook.com] " on the article linked below.
Send SMTP email using System.Net.Mail via Exchange Online (Office 365)
My code seen below.
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress("email12345#company.com")
mail.To.Add("email12345#company.com")
mail.Subject = "Test"
mail.IsBodyHtml = False
mail.Body = "Test"
Dim SmtpServer As SmtpClient = New SmtpClient
SmtpServer.Host = "smtp.office365.com"
SmtpServer.Port = 587
SmtpServer.UseDefaultCredentials = False
SmtpServer.Credentials = New System.Net.NetworkCredential("MyEmail", "MyPass")
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpServer.EnableSsl = True
SmtpServer.TargetName = "STARTTLS/smtp.office365.com"
Try
SmtpServer.Send(mail)
Catch ex As Exception
Response.Write(ex.ToString)
End Try
As it seems this is happening to many people, I would like to know what they are doing to resolve it?
I resolved this issue by creating app password for my outlook365 account. You can create/manage app password as following.
Go to My Account >> Security & Privacy >> Additional Security Verification >> Create and manage app passwords
Create an app password and use it in your code. Hope this will solve your issue
To enable app-password you must have two factor authentication on the account and the administrator (if your account is in an organization) must allow app-passwords on the account (or in the organization)
I'm not a 365 admin and don't know all the settings.
However, we had a similar problem where the sender account did not have the setting "Modern Authentication" enabled for SMTP AUTH.
note that this worked for a long time and suddenly stopped (not sure if Microsoft did some security tightening in late February 2021)
Modern Authentication was enabled for Outlook etc (clients?),
but not for "SMTP AUTH", "IMAP", and "POP"
(I assume this is the "defaults" and recommendation is not to enable Modern Authentication unless you need it.
see the two articles below.
https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/authenticated-client-smtp-submission
Virtually all modern email clients that connect to Exchange Online mailboxes in Office 365 or Microsoft 365 (for example, Outlook, Outlook on the web, iOS Mail, Outlook for iOS and Android, etc.) don't use SMTP AUTH to send email messages.
Therefore, we highly recommend that you disable SMTP AUTH in your Exchange Online organization, and enable it only for the accounts (that is, mailboxes) that still require it. There are two settings that can help you do this:
An organization-wide setting to disable (or enable) SMTP AUTH.
A per-mailbox setting that overrides the tenant-wide setting.
Also good to know about. Will list number of "smtp auth clients".
https://learn.microsoft.com/en-us/microsoft-365/security/office-365-security/mfi-smtp-auth-clients-report?view=o365-worldwide

AD Email Address is inaccessible in ASP.NET website on Server ONLY

I currently have an intranet website set up using IIS. It uses Windows authentication. It looks to Active Directory to get a user's email address through the following two lines of code :
Dim userStr, userEmail As String
userStr = Page.User.Identity.Name.ToString
userEmail = System.DirectoryServices.AccountManagement.UserPrincipal.Current.EmailAddress
Then, this email is used to send an email via SMTP client. My problem is that, when my website is hosted on our server, the email address seems to be inaccessible. This code works perfectly on my localhost. I have my page set up to show the email address once it is accessed, and it just remains blank on the server.
Can anyone tell me what could be going on? It also seems that some of my events are not firing, but I think that is due to the empty email address.
Thank you
I ended up using the following code, which works:
Dim userStr, userEmail As String
userStr = Page.User.Identity.Name.ToString
Using HostingEnvironment.Impersonate()
Dim ctx As PrincipalContext = New PrincipalContext(ContextType.Domain)
Dim xUser As UserPrincipal = UserPrincipal.FindByIdentity(ctx, userStr)
userEmail = xUser.EmailAddress
End Using
It turns out the the code in the original question was trying to return the email address for the identity I am using in IIS. By using this code instead, I am able to return the current user's email address.

Error sending an email with VB.NET using gmail smtp

I have a small website, there is a contact form that uses the gmail's smtp to send an email.
here's the code:
Dim MyMailMessage As New System.Net.Mail.MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("office#mydomain.com")
MyMailMessage.To.Add("test#mydomain.com")
MyMailMessage.Subject = "MSG"
MyMailMessage.IsBodyHtml = True
MyMailMessage.Body = "TEXT"
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("user", "pass")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
Return True
Catch exx As SmtpException
Throw exx
End Try
The error i am getting is :
5.5.4 HELO/EHLO argument invalid, closing connection. ks5sm2862700wjb.13 - gsmtp
Google just started blocking any connection which attempts a HELO/EHLO with incorrect arguments. According to RFC 5321, there should be one argument to EHLO/HELO, and it should be the name of the machine sending the mail.
The most common broken config is not sending any argument, which is what you're doing. The error message isn't that great in that you'd have to notice the two spaces that have your "empty" argument in the middle.
For regular mail sending, giving a hostname that matches the IP address you're sending from (ie, the DNS PTR lookup) is the most correct name to use.
For smtp-msa (ie, user/password based submission to smtp.gmail.com), that's less important, but it should still be the fully qualified domain name of the server, if it's available.
Google isn't enforcing the full requirements of RFC 5321 for this field, yet, but if you're going to fix it, it's best to do so correctly.
I don't see anything on the SmtpClient object to set what to send, so it's either completely broken, or it is making some internal call to get the hostname which is returning an empty string.
I was having the same problem, starting this morning.
We were setting the sender's email address as the argument for EHLO, and it was balking at that. I believe the # was causing the problem. This must be a new requirement, because this worked for years.
I changed the EHLO command to "EHLO google" and it works again.

Email sent from web server causes gmail to treat as phishing. How to get rid of this?

I am sending account activation email from my .net app.
I set the from address to "xyz.support#gmail.com" and from name "xyz" where xyz is the name of the domain i.e. our website.
It was not a problem when we were using Google's SMTP server as I provided credentials to google during sending. But now I am using my own web server's SMTP to send the email.
When I view the activation email in gmail, I get this:
This message may not have been sent by: xyz.support#gmail.com Learn more Report phishing
Is there a way to get rid of this so that gmail and other client don't show this message?
Here is the code:
var smtpClient = new SmtpClient();
var message = new MailMessage();
smtpClient.Host = _config.SMTPServer;
message.From = new MailAddress("xyz.support#gmail.com", "xyz");
message.To.Add("newuser#gmail.com");
message.IsBodyHtml = true;
message.Subject = "Test subject";
message.Body = "Test Body";
smtpClient.Send(message);
Thanks
The domain of the FROM address has to match the domain of the SMTP server that is sending the email, otherwise your message is treated as as spam.
This explains why you avoid the "error" by sending via Google's SMTP server.
The suggestion by IrishChieftain to use SPF helped me, so here is a summary of the steps I did:
1.) First, I also received emails in my GMail inbox that I sent from my sever and that got the "This message may not have been sent by..." warning.
2.) Next, I looked at the source of the email inside GMail (clicke the arrow next to the message and select "Display original"). An excerpt from there was:
Received-SPF: fail (google.com: domain of me#mydomain.com does not
designate 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
So Google directly told me what to do: Add some SPF records in the DNS of my domain "mydomain.com" to get rid of this warning.
3.) Therefore I logged into the control panel of my DNS provider and added two TXT records, something like this:
*.mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
mydomain.com. 180 v=spf1 +a +mx ip4:211.113.37.19 -all
Please note that I entered each line in three separate fields:
One field for *.mydomain.com.
One field for 180 (the TTL, 3 minutes in my example)
One field for v=spf1 +a +mx ip4:211.113.37.19 -all
4.) After that, I waited some time and tried to resend. This succeeded. Google now shows in the original:
Received-SPF: pass (google.com: domain of Received-SPF: pass (google.com: domain of me#mydomain.com designates 211.113.37.19 as permitted sender) client-ip=211.113.37.19;
Please note that I choose the SPF version since the mail server is on a different machine as the web server, so I could not perform the other solution as Mulmot wrote.
There is also an SPF Wizard from Microsoft to correctly generate SPF records. Alternatively, here is yet another SPF generator.

Sending email from classic ASP

SOLVED: Two students gave us the wrong emails, and for some reason the script refused to process more if it encountered a wrong email. I am still wondering why is it so !
I am trying to read a bunch of records from a database, and for each record I am creating some text based on some fields of the record and then sending them as email to the email address provided in the record.
The problem is the email gets sent for only about 5-10 records (it varies, once it sent 5 emails, with cc and everything, next day it sent 7).
After this it comes up with the famous error:
error '8004020f'
/sendEmail.asp, line 139
I have researched all around the internet, and I see many have issues with this error, but not the kind that I am having, in which few emails are send and then it stops.
Also, all emails are being sent to the same domain, the official school email of the students.
Any ideas? Any settings that I might want to ask the website hosting guy to change?
Here is the code.
Dim objMail
Set objMail = CreateObject("CDO.Message")
objMail.From= "someEmail"
objMail.To=rstemp("Email")
objMail.Cc = "someEmail"
objMail.Subject = subjecttext
objMail.HTMLBody=tempData
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")= 2
'Name or IP of remote SMTP server
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.*"
'Server port
objMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
objMail.Configuration.Fields.Update
objMail.Send
set objMail=nothing
tempData = nothing
EDIT: On more debugging, it turns out that when I replace the objMail.To from sending it to each student's email to my own email. It works fine and sends all the emails to me.
Please check first all the Emails is valid and no test email is there. and you can test it with send all emails on same email address for no. of time and can track the problem that is this Email address problem or something else.

Resources