Legal email address gets bounced back - outlook

Platform: Outlook O365
OS: Win 10
Exchange Server in the backend
Cached Mode: On
The email is in the following format (single quotes included)
'First Last (Home)' <client#domain.com>
The bounce back message reads
The format of the email address isn't correct. A correct address looks like this: someone#example.com. Please check the recipient's email address and try to resend the message.
Remote Server returned '550 5.1.3 STOREDRV.Submit; invalid recipient address'
NOTE: The code below does not throw an exception even though single quotes are used instead of the double quotes mentioned in RFC 5322
using System;
namespace mailVerify
{
class Program
{
static void Main(string[] args)
{
string email = "'first last (Home)' <yourname#domain.com>";
try
{
var addr = new System.Net.Mail.MailAddress(email);
Console.WriteLine(addr);
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
}

According to RFC 5322 the name in front of the angle-address must be delimited by double quotes. Apparently the use of single quotes there is not allowed by the standard.
The error message is incomplete since it ignores the name that can appear before the address.

Related

Why is Xamarin inserting '+' signs instead of spaces when sending Emails using the Xamarin.Essentials.EmailMessage?

I am using the code snippet below from here and am getting '+' signs instead of spaces in my Outlook email app. All other text is correct. I do not think I am doing anything fancy with the strings, but I am using string interpolation.
public async Task SendEmail(string subject, string body, List<string> recipients)
{
try
{
var message = new EmailMessage
{
Subject = #"{StoreName} Needs a Payer",
Body = #"It needs a separate payer...",
To = recipients,
//Cc = ccRecipients,
//Bcc = bccRecipients
};
await Email.ComposeAsync(message);
}
catch (FeatureNotSupportedException fbsEx)
{
// Email is not supported on this device
}
catch (Exception ex)
{
// Some other exception occurred
}
}
This is a .NET Xamarin iOS app. What can I do to make sure spaces are used and not '+' signs?
I tried changing the BodyFormat property and got the following results: Setting the BodyFormat to Text does not change the behavior. Still get + signs instead of spaces, but if I use a iOS Mail application, the spaces are fine. If I set it to BodyFormat HTML, the Outlook application just crashes, but the iOS Mail application is fine.
The solution was to update to the latest version of Xamarin.Essentials.
This is an Outlook issue in the iOS app only.
To fix it, use %20 instead of space, and it will work fine with all mail clients.
We can use the Uri.EscapeDataString method to encode the string and then we can pass it in the body and subject.

Can not modify email by using spring framework (Mail-Receiving)

I am working on a project that requires loading incoming emails, process the email that only passed the filtering criteria, in the end mark the email has been SEEN and modify the subject.
There are couple of issues I couldn't figure out:
mail-filter-expression is not working for me. I want to find out the mails that has subject start with "AAA" and the sender's email is "BBB#gmail.com".
Here is my expression:
"(subject matches '(?i)AAA.*')|(sender matches '(?i).BBB#gmail.com.')"
The way how to set user defined flag is very slow. I have to load all email from the open folder and find the email that match with the message Id of current reading message. Is there any better and faster way to do this?
spring-context.xml
<int-mail:imap-idle-channel-adapter id="customAdapter"
store-uri="imaps://XXXX:XXXX#imap.gmail.com:993/inbox"
channel="receiveChannel"
auto-startup="true"
should-delete-messages="false"
should-mark-messages-as-read="true"
java-mail-properties="mailProperties"
mail-filter-expression="(subject matches '(?i)AAA.*')|(sender matches '(?i).*BBB#gmail.com.*')"/>/>
<bean id="mailReceiver" class="com.mfr.email.EmailReceiver"/>
<int:service-activator input-channel="receiveChannel" ref="mailReceiver" method="process"/>
EmailReceiver.java
public void process(Message message) {
System.out.println("Got mail match with filter criteria!");
try {
String subject = message.getSubject();
.........
Folder folder = message.getFolder();
folder.open(Folder.READ_WRITE);
String messageId = ((MimeMessage)message).getMessageID();
Message[] messages = folder.getMessages();
FetchProfile contentsProfile = new FetchProfile();
contentsProfile.add(FetchProfile.Item.ENVELOPE);
contentsProfile.add(FetchProfile.Item.CONTENT_INFO);
contentsProfile.add(FetchProfile.Item.FLAGS);
folder.fetch(messages, contentsProfile);
for (int i = 0; i < messages.length; i++) {
Message loopMsg = messages[i];
String loopMsgId = ((MimeMessage)loopMsg ).getMessageID();
if (loopMsgId.equals(messageId)) {
Flags processedFlag = new Flags();
processedFlag.add(Flags.Flag.ANSWERED);
processedFlag.add(Flags.Flag.SEEN);
loopMsg.setFlags(processedFlag, true);
break;
}
}
folder.expunge();
folder.close(true);
} catch (Exception e) {
e.printStackTrace();
}
}
The common folder protocols (IMAP, POP3) do not allow you to modify messages. You can set the SEEN flag with IMAP, although accessing the message will typically set that for you automatically. Depending on why you're trying to change the Subject, you might be better off setting a user-defined Flag on the message. If you really need to change the Subject, you'll need to copy the message using the MimeMessage copy constructor, modify the copy, append the copy to the folder, and delete the original.
Also, your code above appears to be using a Message object unrelated to the Folder you're opening. You shouldn't do that. Once you close a Folder, all the Message objects from that Folder are invalid. If you reopen the Folder, you need to get a new Message object corresponding to the message you're dealing with (e.g., by looking it up using the UID of the message).

How to validate that password field is empty or not?

public void onMyButtonClick1(View view)
{
final EditText emailValidate = (EditText)findViewById(R.id.emailid);
final TextView passValidate = (TextView)findViewById(R.id.password);
String email = emailValidate.getText().toString().trim();
String pass= passValidate.getText().toString().trim();
String emailPattern = "[a-zA-Z0-9._-]+#[a-z]+\\.+[a-z]+";
// onClick of button perform this simplest code.
if (email.matches(emailPattern)&&(passValidate!=null))
{
//Toast.makeText(this,"valid email address",Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Welcome To Sun Telematics", Toast.LENGTH_SHORT).show();
Intent getStarted = new Intent(getApplicationContext(), FourthActivity.class);
startActivity(getStarted);
/*else
{
Toast.makeText(this, "Field Required", Toast.LENGTH_SHORT).show();
}*/
}
else
{
Toast.makeText(getApplicationContext(),"Invalid email address", Toast.LENGTH_SHORT).show();
}
}
I want to check that password field is empty or not. If it is empty it will not go to the next activity. It will show toast message.
I can validate that field. Where can i do the changes in the code.
You shouldn't check if the instance of the password field is null but whether the string content is actually empty or not. There are various utility libraries for this but it would probably suffice to check !"".equals(pass)
Note that by putting the "" up front you will avoid a NullPointerException even if your string could be null. In this case it wouldn't matter since you already got the string and trimmed it.
I recommend using StringUtils in the common lang library by Apache to handle this kind of stuff though, you could just write StringUtils.isNotEmpty(pass) in that case and it has various utility methods for checking whitespaces, converting strings, etc.

Send a mail from outlook by getting To list from SQl server

I am stuck with a issue from 5 days.
I need a way to attain following requirement.
mailing list is present in Database(SQL server)
I have a mail in Outlook
now i have to send mail to all the 200,000 mail ids in Database
**Note one mail can have only 200 mail IDs so
200,000/200=1000 mails **Note: this 200,000 count is not fixed it will decrease and increase>
like jhon#xyz.com will be present today , next day we may need not send to him
his name might be completely removed (so DL is not an option)
I need a way to automate this
All i have a sleep less nights and coffee cups on my desk
I work in ASP.net any PL which meets this need is fine.
I assume that you know how to create sql statement for what you need and how to retrieve data from database in .NET. This means that only issue is actually sending this from outlook.
Here is an article that describes this in detail and piece of code copied from there.
using System;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn1
{
class Sample
{
public static void SendEmailFromAccount(Outlook.Application application, string subject, string body, string to, string smtpAddress)
{
// Create a new MailItem and set the To, Subject, and Body properties.
Outlook.MailItem newMail = (Outlook.MailItem)application.CreateItem(Outlook.OlItemType.olMailItem);
newMail.To = to;
newMail.Subject = subject;
newMail.Body = body;
// Retrieve the account that has the specific SMTP address.
Outlook.Account account = GetAccountForEmailAddress(application, smtpAddress);
// Use this account to send the e-mail.
newMail.SendUsingAccount = account;
newMail.Send();
}
public static Outlook.Account GetAccountForEmailAddress(Outlook.Application application, string smtpAddress)
{
// Loop over the Accounts collection of the current Outlook session.
Outlook.Accounts accounts = application.Session.Accounts;
foreach (Outlook.Account account in accounts)
{
// When the e-mail address matches, return the account.
if (account.SmtpAddress == smtpAddress)
{
return account;
}
}
throw new System.Exception(string.Format("No Account with SmtpAddress: {0} exists!", smtpAddress));
}
}
}
What I would suggest is to skip using outlook unless that’s really necessary and send email by directly communicating with SMTP server.
Just search for “how to send email from C#” or something similar and you’ll find a ton of examples.

Contact Form EMail not working

I have created a contact page and contact model that has From Subject and Message as string values. Now when I try to send email from my development environment with code below, it won't work. I browsed around a bit looking for a solution but several things are unclear to me since I haven't dealt with this too often.
This is the method I use for sending e-mail. Commented part is also one of the attempts.
The error I get is: System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I realize that this probably has something to do with me being on dev.env., does it? What am I doing wrong?
public class Email
{
public void Send(Contact contact)
{
MailMessage mail = new MailMessage(
contact.From,
ConfigurationManager.AppSettings["ContactEmail"],
contact.Subject,
contact.Message);
//new SmtpClient().Send(mail);
WebMail.Send(ConfigurationManager.AppSettings["ContactEmail"], contact.Subject, contact.Message, null, null, null, false, null);
}
}
Can you send mail like this, instead?
internal static void SendEmail(MailAddress fromAddress, MailAddress toAddress, string subject, string body)
{
var message = new MailMessage(fromAddress, toAddress)
{
Subject = subject,
Body = body
};
var client = new SmtpClient("smtpServerName");
client.Send(message);
}
Ref. asp.net mvc framework, automatically send e-mail
I think you need to check port number in you config file.

Resources