Sending mail - Created By field contains junk information

J

Jack Andersson

I have written a small app that sends a mail, however when I receive the
mail the Created by-field contains information that shoudn't be there.

The code for the reply address is:

InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress("support");

However, when I receive the mail that the app has sent to med the Created By
(i e the reply to-address as I understand it) is

"support".GWIATA.OurCompanyDomain

When I try the following:

InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress("(e-mail address removed)");

the Created By-field becomes:

"(e-mail address removed)"(e-mail address removed)

Why is this? Is it a matter of configuration on the mail server? Or do I
have to set some kind of property before sending mail?
 
G

GaryM

Why is this? Is it a matter of configuration on the mail server?
Or do I have to set some kind of property before sending mail?

It looks like it might be the mail server. Do you have an alternative
SMTP server to test it on?

Also trying putting Javamail in debug mode and watch what it sends to
the server. It should show the reply-to being written, so you can see
if it is going in clean.
 
J

Jack Andersson

It looks like it might be the mail server. Do you have an alternative
SMTP server to test it on?

I've tried to use another mail server with the same result. Even more
strange, the Created By-adress changes only when the sender is in our
company domain, i e

InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress("(e-mail address removed)");

the Created By-field becomes:

"(e-mail address removed)"(e-mail address removed)

But if I use

InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress("(e-mail address removed)");

the Created By-field becomes:

(e-mail address removed)

which is correct.
Also trying putting Javamail in debug mode and watch what it sends to
the server. It should show the reply-to being written, so you can see
if it is going in clean.

No useful information there, I'm afraid.
 
J

Jack Andersson

Here you have it!


import java.util.*;
import java.lang.*;
import java.net.InetAddress;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class MailTST {
public static void main(String[] args)
throws Exception {

Properties props = new Properties();
props = System.getProperties();
props.put("mail.smtp.host", "mail.OurCompanyDomain.com");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true); // Debug mode is activated

// create a message
MimeMessage msg = new MimeMessage(session);

String sFrom = "(e-mail address removed)";
String sTo = "(e-mail address removed)";
String sSubject = "Mailtest with java.";
String sMessage = "Bla bla bla ...";
String sFileName = null;
InternetAddress reply[] = new InternetAddress[1];
reply[0] = new InternetAddress("(e-mail address removed)");
String test = InetAddress.getLocalHost().getHostName();



msg.setFrom(new InternetAddress(sFrom));
msg.setSender(new InternetAddress("(e-mail address removed)"));

msg.setReplyTo(reply);
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(sTo, false));
msg.setSubject(sSubject,"ISO-8859-1");
msg.setSentDate(new Date());


// create and fill the first message part
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(sMessage,"ISO-8859-1");

// create the Multipart and add the first path
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp1);

// create the second message part if file should be attached
if (sFileName != null)
{

int nStart = 0;
int nSlut = 0;
String sTmp1 = "";
nStart = sFileName.indexOf(' ', nStart);
nSlut = sFileName.indexOf(' ', nStart);

if ( nStart >= 0 ) {
sTmp1 = sFileName.substring(0, sFileName.indexOf(' ',
nStart));

MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(sTmp1);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);

while ( nStart <= sFileName.lastIndexOf(' ') )
{
nStart = sFileName.indexOf(' ', nStart);
if ( nStart < 0 )
{
break;
}

nSlut = sFileName.indexOf(' ', nStart + 1);
if ( nSlut < 1 )
nSlut = sFileName.length();

sTmp1 = sFileName.substring(nStart + 1, nSlut);

MimeBodyPart mbp3 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds3 = new FileDataSource(sTmp1);
mbp3.setDataHandler(new DataHandler(fds3));
mbp3.setFileName(fds3.getName());
mp.addBodyPart(mbp3);
nStart = nSlut;
}
}
else {
sTmp1 = sFileName;
MimeBodyPart mbp2 = new MimeBodyPart();
// attach the file to the message
FileDataSource fds = new FileDataSource(sTmp1);
mbp2.setDataHandler(new DataHandler(fds));
mbp2.setFileName(fds.getName());
mp.addBodyPart(mbp2);
}
}


// add the Multipart to the message
msg.setContent(mp);

Transport.send(msg);

}
}
 
J

Jack Andersson

Looks ok to me. Do you know how to send an email manually? My money is
still on the server appending something, but to disprove that you could
perform a manual transaction, writing the Reply-To header into the DATA
part. See this page for help, if you even it need it.

http://www.yuki-onna.co.uk/email/smtp.html

Sadly the problem persists when I send the mail manually, so it must be the
mailserver. Thanks for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top